0
自我控制這是代碼說明: http://jsbin.com/uzapuy/1/edit如何從另一個控制器的內容得到entrie並呼籲失蹤
我希望能夠通過URL訪問測試像這樣:http://jsbin.com/uzapuy/1#/test/2 因爲entrie可能已經存在在客戶端,我想首先檢查它是否從服務器端丟失提取。 沒有DS.Store,這可能嗎?
自我控制這是代碼說明: http://jsbin.com/uzapuy/1/edit如何從另一個控制器的內容得到entrie並呼籲失蹤
我希望能夠通過URL訪問測試像這樣:http://jsbin.com/uzapuy/1#/test/2 因爲entrie可能已經存在在客戶端,我想首先檢查它是否從服務器端丟失提取。 沒有DS.Store,這可能嗎?
在你TestRoute
,你能不能做這樣的事情:
App.TestRoute = Ember.Route.extend({
model: function(params) {
// Find your controller that has the "fetch" method.
var testController = this.controllerFor('test');
// Check if there's an existing model with this ID.
var existingModel = testController.find('id', params.id);
// Determine if we found a model or not.
if (existingModel) {
// If we found an existing model, then we can set this as the model.
return existingModel;
}
// Otherwise we'll fetch it from the server.
return testController.fetch(params.id);
}
});
此外,忍受記住,在你的代碼中,test
變量是undefined
:
var tests = App.Test.create({id: id, name: 'fetched ' + id});
self.set('content', test);
你之後tests
,我假設。
更新了我的代碼片段:http://jsbin.com/uzapuy/5/edit 但是,如果我在testsController中使用* find *方法,我得到了錯誤。如果我使用findProperty方法 - T在搜索結果中什麼也沒有。爲了您的注意,有2個控制器'測試'和'測試'。 – greggyNapalm 2013-02-09 19:08:17
由於'TestController'需要擴展'ArrayController'才能訪問'find' /'findProperty',我認爲這是你需要的。 – Wildhoney 2013-02-10 01:13:35
但它是https://gist.github.com/greggyNapalm/4748934#file-gistfile1-html-L90和53行。 – greggyNapalm 2013-02-10 09:11:18