2015-06-10 68 views
2

我想重新定義我的buildURL,具體取決於同一模型上更改的屬性。例如,如果狀態改變了,我想把它放到一個特定的路線上,如果這個子用戶改變了,我想把它放到另一個路線上。定義buildURL取決於哪些屬性發生了變化

例子:

this.store.find('conversation', conv.id).then(function(conversation){ 
    conversation.set('status', 'opened'); 
    conversation.save();      
}); 

這將使用某種PUT路線,這一點:

this.store.find('conversation', this.get('selectedConv').id).then(function(conversation){ 
    conversation.set('subuser', subuser); 
    conversation.set('url', subuser.get('email')); 
    conversation.save(); 
}); 

,這將使用另一種路線的PUT連壽的變化是在同一個模型製作。這一切都發生在控制器中。

回答

4

您需要自定義conversation適配器,特別是urlForUpdateRecord方法。

最初的方法looks這樣的:

urlForUpdateRecord: function(id, modelName, snapshot) { 
    return this._buildURL(modelName, id); 
}, 

在這種方法中,你需要檢查的快照,並相應地調整URL。

Ember Data的最新版本引入了changedAttributes屬性。這似乎是你需要的。

祝你好運!

+0

不要忘記upvote!^- ^ –

相關問題