木偶ItemView控件如何在变化的重新渲染模式 [英] Marionette ItemView how to re-render model on change
问题描述
我使用的把手模板引擎。结果
所以,我有型号:
I'm using Handlebars template engine.
so, I have Model:
Backbone.Model.extend({
urlRoot: Config.urls.getClient,
defaults: {
contract:"",
contractDate:"",
companyTitle:"",
contacts:[],
tariff: new Tariff(),
tariffs: [],
remain:0,
licenses:0,
edo:""
},
initialize:function(){
this.fetch();
}
});
然后木偶ItemView控件:
then Marionette ItemView:
Marionette.ItemView.extend({
template : templates.client,
initialize: function () {
this.model.on('change', this.render, this);
},
onRender: function () {
console.log(this.model.toJSON());
}
});
然后我把一切为:
and then I call everything as:
new View({
model : new Model({id:id})
})
和,它立刻就出来了我的一个观点,这是很酷。
但该模型获取数据后,它的触发改变,所以我在控制台序列化的模型中看到两次,我看到了第一次空模型,然后进行填充的。
and, it's immediately render a view for me and this is cool. But after the model fetched data it's trigger "change", so I see in console serialised model twice, and I see for first time empty model and then filled one.
不过,该视图不会被更新。
But, the view is NOT updated.
我怎样才能解决这个问题?
How I can fix it?
P.S。我明白了,我可以呼吁取做回调渲染方法。但是我还需要进行进一步操作,当用户将改变模式。
P.S. I understand, that I can call a render method on fetch done callback. But I also need it for further actions, when user will change model.
推荐答案
其实,骨干网和木偶有足够的智慧来做到这一点。结果
问题是模板和数据,我发现它<一个href=\"http://stackoverflow.com/questions/16793422/backbone-marionette-itemview-not-rendering-on-model-change?rq=1\">another问题。所以,我重新检查一切,得到的结果。
Actually, Backbone and Marionette are smart enough to do it.
Problem was in template and data as I found it another question. So, I re-checked everything and got result.
这篇关于木偶ItemView控件如何在变化的重新渲染模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!