在 Ajax request.How 之后重新加载 Backbone.View?
Reload Backbone.View after Ajax request.How?
我在 Backbone.View
到 change
集合中有 ajax 请求:
change: function(model, options){
me = this;
$.ajax({
url: ajaxurl,
type: 'post',
data: {
action: 'getShortcode',
shortcode: model.attributes.shortcode
},
success: function (data) {
me.$el.find('section:eq(' + model.collection.indexOf(model) + ')').replaceWith(data);
me.add( model, model.collection );
}
});
}
但是在 ajax 请求之后,我的另一个 Backbone.View
(通过触发器调用这个 ajax)不再工作,"reload" 我的另一个 Backbone.View
在 ajax 之后强制触发器再次调用 ajax?谢谢!
你应该使用 Backbone.Model 。如果您的模型已经是 Backbone.Model,只需使用 model.set( anObjectWithTheChanges )
即可触发模型中的 change
事件。
然后,只需在视图的 initialize
函数中添加一些代码即可监听模型的变化。类似于:
this.listenTo( this.model, 'change', this.render);
其中 render
是您视图中负责刷新的方法。
我在 Backbone.View
到 change
集合中有 ajax 请求:
change: function(model, options){
me = this;
$.ajax({
url: ajaxurl,
type: 'post',
data: {
action: 'getShortcode',
shortcode: model.attributes.shortcode
},
success: function (data) {
me.$el.find('section:eq(' + model.collection.indexOf(model) + ')').replaceWith(data);
me.add( model, model.collection );
}
});
}
但是在 ajax 请求之后,我的另一个 Backbone.View
(通过触发器调用这个 ajax)不再工作,"reload" 我的另一个 Backbone.View
在 ajax 之后强制触发器再次调用 ajax?谢谢!
你应该使用 Backbone.Model 。如果您的模型已经是 Backbone.Model,只需使用 model.set( anObjectWithTheChanges )
即可触发模型中的 change
事件。
然后,只需在视图的 initialize
函数中添加一些代码即可监听模型的变化。类似于:
this.listenTo( this.model, 'change', this.render);
其中 render
是您视图中负责刷新的方法。