如何将主干模型连接到视图?
这是我第一次使用骨干,我试图弄清楚为什么 console.logging this.model
在我的视图内不会吐出我的模型,它有一些默认值属性。
相反,我得到:
function (){return a.apply(this,arguments)}
这是我的小提琴: http://jsfiddle.net/amit_e/muLjV/33/
(请打开控制台查看结果)
我做错了什么?如何在我的视图中访问我的模型?
This is my first time with backbone and I am trying to figure out why console.logging this.model
inside of my view doesn't spit out my model which has some default attributes.
Instead, I get:
function (){return a.apply(this,arguments)}
Here's my fiddle: http://jsfiddle.net/amit_e/muLjV/33/
(Please open your console to see the results)
What am I doing wrong? How do I get access to my model inside my view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为 View 没有使用
model:Photo
定义单个模型。理想情况下,Model:Photo
必须在集合中定义。您应该在 View 中单独创建一个 Photo 实例。所以,它会起作用。
当我在初始化视图块中添加
var myPhoto = new Photo();
时。我当时发现这很有效。关于Collection的使用:
Collection是一组Model。因此,您应该在视图中的任何位置定义它(初始化或渲染或自定义函数)。更具体地说,集合
在MVC架构中用于对模型进行集中操作。例如,在您的情况下,相册可能是照片的集合。
您可以在相册中的照片上存储多个实例。相册将在搜索、排序、添加、删除照片等操作中对您很有用。
As View doesn't define a single model with
model:Photo
. Ideally,Model:Photo
has to be defined in a collection.You should create an instance of Photo inside View seperately. So, it will work.
When I added
var myPhoto = new Photo();
in initialize block of view. I found this working then.About usage of Collection:
Collection is a group of Models. So, You should define it anywhere in View ( Initialize or render or cutom function). More specifically, Collection
is used in MVC architecture to perform operation on models collectively. For example, In your case Album could be a collection of Photos.
You can store multiple instances on photo in Album. Album will be useful to you in operations like search, sort, add, delete of photos.