在 Backbone.js 中,我应该创建静态列表集合还是只是将它们硬编码到 UI 中?
我有一个 Web 应用程序,我想使用 Backbone.js。我有一个常见“项目”列表,用户不会直接编辑这些项目。这基本上会显示为屏幕左侧的菜单供您选择。当用户选择一个项目时,将生成一个他们可以自定义的“项目实例”。
我只是想知道这个项目/模板的静态列表是否应该由 Backbone.js 处理,或者是否应该只是硬编码。对列表使用 Backbone Collection/Models 的价值在于,每个项目都将具有另一个 Backbone.Model 属性,当从列表中选择该项目时,该属性将被实例化。例如,当选择 HTMLImageChoice 项时,将导致 HTMLImage 被实例化。
我很难找到易于遵循的 Backbone.js 示例,这些示例不是很做作。
I have a web app that I want to use Backbone.js for. I have a list of common "items" which will not be edited by the user directly. This will appear essentially as a menu to choose from on the left side of the screen. When a user selects an item an "item instance" will be generated which they will customize.
I'm just wondering if this static list of items/templates should be handled by Backbone.js or if it should just be hardcoded. The value in using a Backbone Collection/Models for the list is that each item will have another Backbone.Model property that will be instantiated when that item is selected from the list. e.g. the HTMLImageChoice item, when selected, will result in an HTMLImage being instantiated.
I'm having trouble finding easy to follow examples of Backbone.js which are not very contrived.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
主干中的集合是模型的集合。看起来您只是在谈论硬编码的字符串数组,这完全不是模型。也许您希望将该数组作为属性挂在模型上,但这与主干非常接近。
Collections in backbone are collections of models. It seems like you are just talking about a hardcoded array of strings, which are totally not a model. Maybe you would want to hang that array off of a model as a property, but that is as close to backbone as it will get.