Backbone.js - 将 2 个模型传递给 1 个视图
我试图将 2 个模型传递给视图,但似乎不起作用。这是我的示例: http://jsfiddle.net/kahhor/jp4B6/14/ 作为您可以看到第二个警报显示未定义...
可能是我的方法错误。我想做的是:在 View1
中将事件 'change'
绑定到 Model1
...而不是单击 中的按钮View2
,调用Model1
中更改值的函数,并自动渲染View1
,因为它绑定到了更改事件。
但不要忘记 View2
也有自己的 Model2
,它是我在视图外部创建的,然后像 new View2({model:Model2}) 一样传递它;
。
一开始可能看起来很混乱,但我认为主干可以做的事情很简单。我只是不知道该怎么做:)
谢谢,
I'm trying to pass 2 models to the view, but it seems it is not working. Here is my example: http://jsfiddle.net/kahhor/jp4B6/14/ As you can see second alert is showing undefined...
May be I have wrong approach. What I'm trying to do is: in View1
bind event 'change'
to Model1
... Than by clicking button in View2
, call function in Model1
which changes value, and automatically render View1
, since it was binded to change event.
But don't forget that View2
has also its own Model2
, which I created outside the view and than passed it like new View2({model:Model2});
.
It might looked confusing at first, but I think it is simple thing that backbone can do. I just don't know how to do it :)
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以像这样访问自定义参数(选项)
:
结论:视图的“无法识别的选项”可以在
this.options
中找到you can access custom parameters (options) from
like this:
Conclusion: "unrecognized options" of a view can be found in
this.options
我刚刚通过 Google 找到了这个问题和 Sled 的答案,它对我帮助很大 - 但只是为了更新这个 2 年前的问题,也许可以让其他一些 Google 员工免于头痛:
Vitaliy 对类似问题的回答向您展示了如何:
I just found this question and Sled's answer via Google and it helped me a lot - but just to update this 2 year old question and perhaps save some other Googlers the headache:
Vitaliy's Answer on a similar question shows you how:
添加此补丁并直接传递任何选项以查看。
Add this patch and pass any options directly to view.