我想知道 emberViews 之间是否可以交互?
使用 Controller ,我进行了类似的设置,效果很好。
>> Index Controller
var StudyController = Ember.ArrayController.extend({
needs: ['study/study'],
actions: {
filterStudies: function(){
console.log('FILTER ENGAGED!');
this.transitionToRoute('study.search', this.get('search'));
}
}
});
在 StudyIndex HBS 中我使用了这个,它现在在需求标签之间的 Controller 中处理
{{action 'deleteStudy' this target='controller.controllers.study/study'}}
最佳答案
这在 View 之间不能直接实现。 相反,您应该在 Controller 的帮助下实现间接通信。请考虑以下两个 View 及其关联 Controller 的虚构示例:
您应该将操作从 FirstView 发送到 FirstController(需要 SecondController)。然后 Controller 将操作转发给 SecondController。 SecondController 执行它需要执行的任何操作(例如设置属性),从而通知 SecondView。
更新:示例
请注意:我假设您需要将一个对象从 FirstView
发送到 SecondView
。如果您的事件不需要参数,则可以省略它。
查看:
App.FirstView = Ember.View.extend({
submit : function(){
//do the view part of your logic
var object = //do whatever you may need
this.get("controller").send("actionInController", object); //you do not have to send a object, if you do not need to
}
});
Controller :
App.FirstController = Em.ObjectController.extend({
needs : ['second'],
actions : {
submitInController: function(object) {
// do the controller part of your logic
this.get("controllers.second").methodOfSecond(object);
}
},
});
App.SecondController = Em.ObjectController.extend({
someProperty : null,
methodOfSecond: function(object) {
// set whatever property so that the second view gets informed
this.set("someProperty", object);
}
});
关于javascript - Ember 在 View 之间使用 [needs],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22174853/