2013-07-15 20 views
1

我創建了一些模型App.Markets
在這裏我要顯示「你好世界」。
檢測事件當模型在emberjs動態創建

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型號的新紀錄,我不能看到這條消息。

+1

它是否奏效?讓我知道它是否有幫助,如果沒有,我可以進一步改進我的答案 – intuitivepixel

回答

0

我不知道你的應用程序設置是怎樣的,但看看這個簡單的demo,使用FixtureAdapter爲簡單起見,誰顯示它的工作。

讓我知道它是否有幫助。

1

當適配器從API獲得確認記錄已保存時,會觸發didCreate鉤子。如果你看不到這條消息,可能是因爲調用你的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(); 
}