gpt4 book ai didi

ember.js - 从索引 Controller 发送的 Ember 操作未由索引路由处理

转载 作者:行者123 更新时间:2023-12-02 04:47:45 24 4
gpt4 key购买 nike

https://emberjs.jsbin.com/depoxiseve/edit?js,output

当观察 Controller 上的模型变化时,索引路由不会处理从索引 Controller 发送的操作。它抛出一个 Action 未处理的错误。它将在应用程序路由中得到处理。为什么是这样?是因为索引路由尚未激活吗?有什么方法可以让它发挥作用吗?

App.IndexRoute = Ember.Route.extend({
model: function() {
return ['red', 'yellow', 'blue'];
},
actions: {
test: function() {
console.log('test');
}
}
});

App.IndexController = Ember.Controller.extend({
test: function() {
this.send('test');
}.observes('model')
});

最佳答案

目前 JSBin 似乎坏了,但我想如果你想让 Action 冒泡,你需要在你的 Controller 上创建一个 test Action ,然后 return true 来自 Action 。因为 this.send('test'); 会发送一个测试 Action 给 this,它实际上是 Controller 。

所以:

App.IndexRoute = Ember.Route.extend({
model: function() {
return ['red', 'yellow', 'blue'];
},
actions: {
test: function() {
console.log('test');
}
}
});

App.IndexController = Ember.Controller.extend({
test: function() {
this.send('test');
}.observes('model'),
actions: {
test: function() {
return true;
}
}
});

附言你想做什么?现在通常建议尽可能避免观察者(似乎是性能问题)。

关于ember.js - 从索引 Controller 发送的 Ember 操作未由索引路由处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31477075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com