简体   繁体   English

骨架.js一个模型被多个视图改变了吗?

[英]backbone.js one model being changed by multiple views?

Okay, I've only started learning backbone.js last night and I have to admit I am a tad baffled at the moment. 好的,我从昨晚才开始学习骨干.js,我不得不承认我现在有点困惑。 My scenario is relatively simple, I have one HTML table with an id of #checkout_table. 我的场景相对简单,我有一个ID为#checkout_table的HTML表。 This table has 4 rows. 该表有4行。 It will always have 4 rows, it will never decrease or increase the number of rows. 它总是有4行,它永远不会减少或增加行数。 There are various other form elements on the page which I want to be able to effect the values of the rows. 页面上还有其他各种表单元素,希望它们能够影响行的值。 Eventually this will be via ajax, but that doesn't seem important for this example. 最终,这将通过ajax完成,但这对于本示例而言似乎并不重要。 Here is what I came up with: http://jsfiddle.net/XYZas/ 这是我想出的: http : //jsfiddle.net/XYZas/

In the backbone docs it says that, "The general idea is to organize your interface into logical views, backed by models, each of which can be updated independently when the model changes, without having to redraw the page. Instead of digging into a JSON object, looking up an element in the DOM, and updating the HTML by hand, you can bind your view's render function to the model's "change" event — and now everywhere that model data is displayed in the UI, it is always immediately up to date." 在主干文档中,它说:“一般的想法是将界面组织成逻辑视图,并由模型支持,当模型更改时,每个视图都可以独立更新,而不必重新绘制页面。不必挖掘JSON。对象,在DOM中查找元素并手动更新HTML,您可以将视图的render函数绑定到模型的“ change”事件-现在,在UI中显示模型数据的任何地方,它始终可以立即日期。”

Am I on the right track to do this? 我是否在正确的轨道上做到这一点? Is passing around an instance of the CheckoutTable model as a global variable really the right way to do this or would you do it differently? 将CheckoutTable模型的实例作为全局变量传递真的是正确的方法吗?还是会有所不同?

Thanks in advance for your help. 在此先感谢您的帮助。

Like czar mentioned: Model represents your data, Views use your models to render it into HTML for display. 就像提到的czar一样:模型代表您的数据,视图使用模型将其呈现为HTML以进行显示。

Your app should look more along the lines of this: http://jsfiddle.net/XYZas/2 您的应用应该看起来像这样: http : //jsfiddle.net/XYZas/2

Also, check out this great tutorial: http://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/ 另外,请查看此出色的教程: http : //www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM