2013-02-09 18 views

回答

0

在你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,我假設。

+0

更新了我的代碼片段:http://jsbin.com/uzapuy/5/edit 但是,如果我在testsController中使用* find *方法,我得到了錯誤。如果我使用findProperty方法 - T在搜索結果中什麼也沒有。爲了您的注意,有2個控制器'測試'和'測試'。 – greggyNapalm 2013-02-09 19:08:17

+0

由於'TestController'需要擴展'ArrayController'才能訪問'find' /'findProperty',我認爲這是你需要的。 – Wildhoney 2013-02-10 01:13:35

+0

但它是https://gist.github.com/greggyNapalm/4748934#file-gistfile1-html-L90和53行。 – greggyNapalm 2013-02-10 09:11:18

相關問題