2013-04-08 84 views
1
App.Router.map(function() { 
    this.resource('documents', { path: '/documents' }, function() { 
     this.route('edit', { path: ':document_id/edit' }); 
    }); 
    this.resource('documentsFiltered', { path: '/documents/:type_id' }, function() { 
     this.route('edit', { path: ':document_id/edit' }); 
     this.route('new'); 
    }); 
}); 

路線,這個控制器基本上過渡到過濾文件灰燼路由器transitionTo嵌套使用參數

App.DocumentsController = Ember.ArrayController.extend({ 
    subview: function(context) { 
    Ember.run.next(this, function() { 
     //window.location.hash = '#/documents/'+context.id; 
     return this.transitionTo('documentsFiltered', context); 
    }); 
}, 
}); 

我的問題是,當頁面的哈希改變這個代碼工作正常子視圖事件。

但是,當我NOT /對的location.hash位和W /灰燼運行上面的代碼W¯¯本地transitionTo我得到一個神祕的

Uncaught TypeError: Object [object Object] has no method 'slice'

任何線索?

感謝

UPDATE:

App.DocumentsFilteredRoute = Ember.Route.extend({ 
model: function(params) { 
    return App.Document.find({type_id: params.type_id}); 
}, 
}); 

{{#collection contentBinding="documents" tagName="ul" class="content-nav"}} 
<li {{action subview this}}>{{this.nameOfType}}</li> 
{{/collection}} 
+0

如果沒有看到對子視圖()的調用,就無法確切地說出解決方案。但是在這種情況下Ember似乎期待一個陣列。你需要顯示你對subview()的調用和你的DocumentsFilteredRoute的代碼來找到問題。 – mavilein 2013-04-08 21:38:20

+0

這只是一個簡單的香草餘燼路線w /模型定義。 – Everydaypanos 2013-04-08 22:31:58

回答

4

的問題是,你的模型鉤子返回一個數組,而在你的transitionTo您使用的是單個對象。作爲一個經驗法則,您對transitionTo的調用應該傳遞您的模型鉤子返回的相同數據結構。下面這個經驗法則我會建議做到以下幾點:

App.DocumentsController = Ember.ArrayController.extend({ 
    subview: function(document) { 
     var documents = App.Document.find({type_id: document.get("typeId")}); 
     Ember.run.next(this, function() { 
      return this.transitionTo('documentsFiltered', documents); 
     }); 
    } 
}); 

注:我假設TYPE_ID被存儲在屬性的typeid。也許你需要根據自己的需要進行調整。