//当我单击kickassessor按钮时,它将更新数据库,但视图未更新。这是我的代码。
返回Marionette.ItemView.extend({
initialize : function ( options ) {
var self = this;
_.bindAll( this );
_.each( options, function ( value, key ) {
self[ key ] = value;
} );
//this.model.on('change', this.render, this);
return this;
},
// Ui events hash
events : {
'mouseover a.btn' : 'showTooltip',
'click #kickBtn' : 'kickAssessor',
'click #deleteBtn' : 'deleteUser'
},
// on render callback
onRender : function() {
this.ui.kickBtn.tooltip( {
title : 'Kick as assessor'
} );
this.ui.deleteBtn.tooltip( {
title : 'Delete user'
} );
},
kickAssessor : function ( ) {
this.model.save({role:'2'});
//on success it should update the itemview
},
最佳答案
您可以添加modelEvents
哈希(https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.itemview.md#modelevents-and-collectionevents):
modelEvents: {
"sync": "render"
}
每当您的模型与服务器同步时,以上都会调用
render
函数。关于marionette - Backbone.marionette重新渲染模型更改 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20602769/