我正在尝试实现路由器事件并使用路由器的发送功能来触发路由器上的事件。但无法获得有关此的任何文档。
我想要实现的是我正在从控制器/视图中引发一个事件以从服务器获取数据。并且事件从服务器异步获取数据,当成功获取数据时,我想从调用事件的位置初始化视图的子视图,即我需要知道何时获取数据。但我认为路由器上的事件不会返回任何让我知道通话何时结束的信息。
类似的东西:
查看:
Em.View.extend({
click: function(){
var recordsPromise = this.get('controller.target').send('getRecords');
recordsPromise.done(this.initiateProtocol);
},
showChild: false,
initiateProtocol: function(){
//this showChild is used as a condition in the template to show/hide
// the childview. And is being set after the call completed
// successfully
//here childOneView is present some other js file and is fetched using requirejs
require(['childOneView'], $.proxy(function(childOneView){
this.set('childOne', childOneView.extend({
templateName: 'childOne'
});
this.set('showChild', true);
}, this));
}
}
路由器
Em.Route.extend({
events: {
getRecords: function(){
//make an ajax call to fetch the records and return the ajax as a
// promise
}
}
});
模板
{{#if view.showChild}}
{{view view.childOne}}
{{/if}}