//当我点击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
},
答案 0 :(得分:9)
您可以添加modelEvents
哈希(https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.itemview.md#modelevents-and-collectionevents):
modelEvents: {
"sync": "render"
}
每次模型与服务器同步时,上面都会调用render
函数。