sách gpt4 ăn đã đi

javascript - EmberJS Action - 当包装在 `actions` 中时从另一个 Action 调用一个 Action

In lại 作者:IT王子 更新时间:2023-10-29 03:03:16 26 4
mua khóa gpt4 giày nike

当包裹在 EmberJS Controller 的 actions 中时,如何从另一个 Action 调用一个 Action ?

使用现已弃用的方式定义操作的原始代码:

//app.js
App.IndexController = Ember.ArrayController.extend({
// properties
/* ... */

// actions
actionFoo: function() {
/* ... */
this.actionBar();
},
actionBar: function() {
/* ... */
}
});

//app.html


但是,对于 EmberJS 1.0.0,我们会收到弃用警告,指出 Action 必须放在 Controller 内的 Action 对象中,而不是像上面那样直接放在 Controller 中。

根据建议更新代码:

//app.js
App.IndexController = Ember.ArrayController.extend({
// properties
/* ... */

// actions
hành động: {
actionFoo: function() {
/* ... */
this.actionBar(); //this.actionBar is undefined
// this.actions.actionBar(); //this.actions is undefined
},
actionBar: function() {
/* ... */
}
}
});

//app.html


但是,我发现 Action 中定义的一个函数不可能调用另一个函数,因为 cái này 对象似乎不再是 Controller 。

我该怎么做呢?

câu trả lời hay nhất

Bạn có thể sử dụng send(actionName, arguments) phương pháp.

App.IndexController = Ember.ArrayController.extend({
hành động: {
actionFoo: function() {
alert('foo');
this.send('actionBar');
},
actionBar: function() {
alert('bar');
}
}
});

这是一个包含此示例的 jsfiddle http://jsfiddle.net/marciojunior/pxz4y/

关于javascript - EmberJS Action - 当包装在 `actions` 中时从另一个 Action 调用一个 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18743760/

26 4 0
Xem sitemap của VNExpress