我想在我的视图中检索特定ID号的模型。以下是我的控制器的样子(API工作正常):
控制器
var EventController = Marionette.Controller.extend({
initialize: function(options){
this.model = options.model;
this.mainRegion = options.mainRegion;
},
edit: function(id) {
var _me = this;
//this is my model
var event = new Event({
id: id
});
event.fetch({
success: function(){
//this is my layout
_me.eventLayout = new EventView({
model: event
});
_me.mainRegion.show(_me.eventLayout);
}
});
}
});
场景如下:
答案 0 :(得分:0)
试试这个:
edit: function (id) {
var _me = this, event, eventView;
event = new Event({ id: id });
eventView = new EventView({ model: event });
event.fetch().done(function () {
_me.mainRegion.show(eventView);
});
}