Backbone.js 中的模型与视图
从几天开始,我开始工作/学习 backbone.js。我已阅读他们网站上的文档。我还阅读了此处提供的一些教程。
根据我的理解,视图和模型之间存在一些主要差异。
- 只有视图有“el”。 为什么模型中没有它?
- 只有模型有“get”、“set”、“save”方法。
- 只有模型具有获取、保存、销毁、验证等功能 方法,明确,有。
根据 此处 的 Hello World 示例,视图也可以完成模型可以做的事情。
- 两者都有扩展、渲染、初始化、getter、setter 方法。
- 两者都可以使用 toJSON 转换为 JSON。
因此,我对模型和视图感到困惑。何时使用每一项?
我的问题是..模型和视图之间的实际区别是什么?使用模型/视图有哪些不同的情况?什么应该适合用于显示(渲染)?
任何优秀的 @Backbone.js 都可以用实际场景来解释吗?
你的帮助将使我的理解更加清晰。
From couple of days, I have started working/learning the backbone.js. I have read documentation on their site. I have also read few tutorials available here.
As per my understanding below are few major differences between Views and Models.
- Only view has 'el'. Why it is not there in Model ?
- Only Models have 'get','set', 'save' methods.
- Only Models have functions like fetch, save, destroy, validate
methods,clear,has.
According Hello World examples here, View can also do the things Models can do.
- Both have extend, render, initializer, getter setter methods.
- Both can be converted into JSON using toJSON.
hence, I am confused between Models and Views. When to use each one ?
my question is.. what is practical difference between Models and Views? What are different situations to use Models/Views ? What should be appropriate to use for displaying(render)?
Can anyone good @ Backbone.js explain with practical scenario ?
Your help will make my understanding much clear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模型和视图不是主干术语。您可以先阅读 MVC 范例。
模型包含数据和数据操作的逻辑。视图描述了如何显示该数据。
因此,只有视图有“el” - 因为它是在显示数据时使用的。
Getter 和 Setter 是根据 MVC 范式进行建模的。
Model and Views are not Backbone terms. You can read about MVC paradigm first.
Model contain data and logic for data manipulations. View describes how this data should be displayed.
Hence only View have 'el' - because this it is used while displaying data.
Getters and setters are in model according to MVC paradigm.