Backbone.js的 - 经过2模型1视图 [英] Backbone.js - passing 2 models to 1 view
问题描述
我想2模型传递给视图,但现在看来,这是行不通的。这里是我的例子: http://jsfiddle.net/kahhor/jp4B6/14/ 正如你可以看到第二个警告正显示出不确定...
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...
可能是我有错误的做法。我正在试图做的是:在视图1
绑定事件改变
到型号1
...比通过点击视图2按钮
在型号1
通话功能,改变价值,并自动渲染视图1
,因为它被绑定到更改事件。
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.
但是,不要忘记,视图2
也有其自身的模型2
,这是我的观点之外,比创建通过它像新视图2({模型:模型2});
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 :)
谢谢,
推荐答案
您可以从
window.PopupView = new PopupView({ model: LeftNotificationM, model2: PopupM});
是这样的:
window.PopupView = Backbone.View.extend({
// code left out
initialize: function () {
this.model.bind('change:notification_num', this.render);
alert(this.model);
// your model2 option:
alert(this.options.model2);
},
// code left out
});
结论:鉴于识别的选项可以在 this.options
这篇关于Backbone.js的 - 经过2模型1视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!