我创建了一些模型 App.Markets
在这里我将显示“hello world”。
App.DashboardController = Ember.ObjectController.extend({
test: function(){
var post = App.Markets.createRecord({
name: "NAME123",
created: "CREATED123"
});
post.one('didCreate', function() {
console.log("hello world");
});
post.save();
}
但是当我在 App.Markets 模型中创建新记录时,我看不到此消息。
最佳答案
当适配器从您的 API 获得记录已保存的确认时,将触发 didCreate
Hook 。如果您看不到此消息,可能是因为调用您的 API 时出错。
要查看发生了什么,请将模型的 stateManager.enableLogging
属性设置为 true。完成此操作后,您将能够在模型在状态之间转换时看到 console.log 消息
App.DashboardController = Ember.ObjectController.extend({
test: function(){
var post = App.Markets.createRecord({
name: "NAME123",
created: "CREATED123",
"stateManager.enableLogging": true
});
post.one('didCreate', function() {
console.log("hello world");
});
post.save();
}
关于javascript - 在 emberjs 中动态创建模型时检测事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17646764/