Prevent Backbone collection reset

I am new to Backbone. I see this in every backbone app: var List = Backbone.collection.extend({ model: model }); var myList = new List(); I am a bit confused about this. This script is included in a page, and when the page is reloaded or opened again and again, it will keep instantiate new collection doesn't it? Whenever I save some models into this collection, things are still fin

防止骨干收集重置

我是Backbone的新手。 我在每个主干应用中都看到了这一点 var List = Backbone.collection.extend({ model: model }); var myList = new List(); 我对此有点困惑。 这个脚本包含在一个页面中,当页面被重新加载或者一次又一次地打开时,它会保持实例化新的收集不是吗? 每当我将一些模型保存到这个集合中时,事情仍然很好。 但是,当我开始重新加载页面或再次打开页面时,它将再次实例化具有相同名称的新集合,并且

Backbone Collection communicating with Backbone Models

I'm trying to understand what the best practice is for communicating between the different components of a Backbone project. I've been re-implementing the Backbone version of TodoMVC and my question is around removing models from the collection object. I understand that Backbone model instances trigger a change event whenever any of its model properties are modified via .set() and that

骨干集合与主干模型进行通信

我试图理解在Backbone项目的不同组件之间进行通信的最佳实践。 我一直在重新实现TodoMVC的Backbone版本,我的问题是从集合对象中删除模型。 我了解,Backbone模型实例通过.set()修改其任何模型属性时会触发更改事件,并且与模型实例关联的视图应该从.listenTo()更改模型实例并重新呈现。 但是,模型和收集对象之间的通信的最佳实践是什么? 例如, 从收集对象中删除模型时,通信应如何工作? 下面是我的想法:当模型被移

creating new entities in Backbone Marionette for related models

I've built the backbone app with one model ("conference"). Now I added second model ("talk"). talks belongs to conference, conference has many talks. The nested json is created and it is easy to render it into single-conference template with .eco like this: I can basically build nested json and render nested attributes, no problem but is it a good architecture? Later

在Backbone Marionette中为相关模型创建新实体

我用一个模型(“会议”)构建了骨干应用程序。 现在我添加了第二个模型(“谈话”)。 会谈属于会议,会议有很多谈话。 嵌套的json被创建,并且很容易使用.eco将其转换为单会议模板,如下所示: 我基本上可以构建嵌套的JSON并呈现嵌套的属性,没有问题,但它是一个很好的体系结构吗? 后来它会有更多的图层,每个演讲都会有很多评论。 我该做什么? 我应该建立新的实体“会谈”并使用骨干协会? 处理模型关系的正确方法是

relational cannot instantiate two RelationalModel objects

I am trying to implement BackboneRelational and keep getting "Cannot instantiate more than one Backbone.RelationalModel with the same id per type!" class App.Models.User extends Backbone.RelationalModel urlRoot : '/api/users' idAttribute: 'id' relations: [ type: Backbone.HasMany key: 'plots' relatedModel: 'App.Models.Plot' collectionType: 'App.Collections.Plots

relational不能实例化两个RelationalModel对象

我正在尝试实现BackboneRelational并不断获得 “不能实例化每个类型具有相同ID的多个Backbone.RelationalModel!” class App.Models.User extends Backbone.RelationalModel urlRoot : '/api/users' idAttribute: 'id' relations: [ type: Backbone.HasMany key: 'plots' relatedModel: 'App.Models.Plot' collectionType: 'App.Collections.Plots' includeInJSON: false reverseRelation:

How to get cursor position from multiline RichTextArea in GWT?

I've already read the former article "How to get cursor position or location from RichTextArea in GWT". And the solution work so far. After my implementation I was able to track the cursorposition as long as I wrote a single line. I have no clue how to alter the solution to track the cursor position over more than one line. Error-example: "My name is Tharmar.|" Position = 1

如何从GWT中的多行RichTextArea获取光标位置?

我已经阅读过前面的文章“如何从GWT中的RichTextArea获取游标位置或位置”。 迄今为止,这个解决方案工作。 在我实现后,只要我写了一行代码,就能够跟踪游标位置。 我不知道如何改变解决方案来跟踪超过一行的光标位置。 错误示例: "My name is Tharmar.|" Position = 19(19) => correct "My name is Tharmar. and I hope someone can help me|" Position = 30(49) => incorrect (int) = correct position |=cur

How do you get the cursor position in a textarea?

I have a textarea and I would like to know if I am on the last line in the textarea or the first line in the textarea with my cursor with javascript. I thought of grabbing the position of the first newline character and the last newline character and then grabbing the position of the cursor. var firstNewline = $('#myTextarea').val().indexOf('n'); var lastNewline = $('#myTextarea').val().lastIn

你如何获得textarea中的光标位置?

我有一个textarea,我想知道如果我在textarea的最后一行或textarea的第一行,并且使用javascript指定了光标。 我想抓住第一个换行符和最后一个换行符的位置,然后抓住光标的位置。 var firstNewline = $('#myTextarea').val().indexOf('n'); var lastNewline = $('#myTextarea').val().lastIndexOf('n'); var cursorPosition = ?????; if (cursorPosition < firstNewline) // I am on first line. else if (cursorPos

Get caret (cursor) position in contentEditable area containing HTML content

I have contentEditable element (can be p, div, ...) and I would like to get caret (cursor) position in it. I can normally achieve it with this piece of code: var position = window.getSelection().getRangeAt(0).startOffset; This works fine while the element contains just text. But when the element contains some HTML formatting, the returned position is relative to caret position within included

在包含HTML内容的contentEditable区域中获取插入(光标)位置

我有contentEditable元素(可以是p,div,...),我希望在其中插入光标(光标)位置。 我通常可以用这段代码实现它: var position = window.getSelection().getRangeAt(0).startOffset; 这工作正常,而元素只包含文本。 但是当元素包含一些HTML格式时,返回的位置与包含的HTML元素中的插入位置有关。 我们假设contentEditable元素的内容是这样的: AB<b>CD</b>EF 如果插入符号位于<b></b> ,让

Get a range's start and end offset's relative to its parent container

Suppose I have this HTML element: <div id="parent"> Hello everyone! <a>This is my home page</a> <p>Bye!</p> </div> And the user selects "home" with his mouse. I want to be able to determine how many characters into #parent his selection starts (and how many characters from the end of #parent his selection ends). This should work even if he sele

获取范围的开始和结束偏移量相对于其父容器

假设我有这个HTML元素: <div id="parent"> Hello everyone! <a>This is my home page</a> <p>Bye!</p> </div> 用户用他的鼠标选择“家”。 我希望能够确定他选择的#parent多少个字符(以及他的选择结束时#parent末尾有多少个字符)。 即使他选择了一个HTML标签,这也应该起作用。 (我需要它在所有浏览器中工作) range.startOffset看起来很有希望,但它只是相对于范围的直接容器

Generating PDF files with JavaScript

I'm trying to convert XML data into PDF files from a web page and I was hoping I could do this entirely within JavaScript. I need to be able to draw text, images and simple shapes. I would love to be able to do this entirely in the browser. I've just written a library called jsPDF which generates PDFs using Javascript alone. It's still very young, and I'll be adding features

使用JavaScript生成PDF文件

我试图从网页将XML数据转换成PDF文件,并希望我可以在JavaScript中完全做到这一点。 我需要能够绘制文字,图像和简单的形状。 我希望能够完全在浏览器中完成此操作。 我刚刚写了一个名为jsPDF的库,它仅使用Javascript生成PDF。 它还很年轻,我很快就会添加功能和错误修复。 还提供了一些不支持Data URI的浏览器的解决方法。 它根据自由MIT许可证获得许可。 在我开始写作之前,我遇到了这个问题,并认为我会回来让你知

why does my d3 force layout explode

I am trying to construct a d3 force layout, and it's mostly working, but the first second or so of the animation is kind of wacky. I start all the nodes in the middle of the window, and they end up more or less where I want them to, but the first thing they do is blast out to the edges of the window or beyond before settling down. The layout is eventually doing more or less what I want it t

为什么我的D3力布局爆炸

我正在尝试构建一个d3部队布局,而且大部分都在工作,但动画的第一秒左右就很古怪。 我开始在窗口中间的所有节点,它们或多或少地以我想要的方式结束,但是他们所做的第一件事是在安定下来之前将其吹到窗口的边缘或更远处。 布局最终或多或少地做了我想要的,但是由于起初它是多么古怪,我无法真正地将它展示给当前状态的客户。 我已经尝试了很多重力,充电,链接距离和摩擦值,但似乎我只能通过改变条件来摆脱这种行为,所