2014-10-08 68 views
1

我目前正在使用Yeoman Ember Generator构建一个应用程序应用程序。this.resource显示空白页,但返回模型(使用console.log())

这是我的模板文件夹结构看起来像:

template 
    |---requisitions 
      |---draft.hbs 
      |---pending.hbs 
      |---waiting.hbs 
    requisitions.hbs 
    app.hbs 
    application.hbs 

这是我router.js

Metabuyer.Router.map(function() { 
    this.route('app'); 
    this.resource('requisitions', function(){ 
     this.resource('draft'); 
     this.resource('pending'); 
     this.resource('waiting'); 
    }); 
}); 

在我DS.Store,我有工作就好了申请模式。

Metabuyer.RequisitionsRoute = Ember.Route.extend({ 
    model: function() { 
     return this.store.findAll('requisition'); 
    } 
}); 

草案,未决和等待航线共享相同的申请的模式,但根据他们的需要过滤它,如下面

Metabuyer.DraftRoute = Ember.Route.extend({ 
model: function(params){ 
    var filterResult = this.store.filter('requisition', function(requisition){ 
     return requisition.get('state') === 'draft'; 
    }); 
    console.log(test); 

    return filterResult; 
    }); 
} 

});

我的问题是。 当我在我的路由器中使用this.resource('draft')时,我的页面(空白页面)中没有呈现任何东西,但在我的控制台中,正在返回过滤的对象。

如果我使用this.route('draft')页面被渲染,但页面内容没有被过滤,或者我应该说,我的Metabuyer.DraftRoute没有被调用。

非常感谢你的帮助,:'(

回答

3

http://emberjs.com/guides/routing/defining-your-routes/

路由资源下筑巢搭资源的名称加上他们为他们的路线名称name

父路由也需要索引路由

因此导航到/requistions加载了RequesitionsRouteRequisitionsIndexRoute您需要将模型设置为RequisitionsIndexRoute并使用RequisitionsIndexController等。您需要将requisitions.hbs重命名为index.hbs并将其移至请购单目录。

您还需要与母公司前缀草稿路由对象的名称,以便DraftRoute成为RequisitionsDraftRoute和相同的控制器,视图等

+0

非常感谢! :) 我很紧张整天看着我的代码。应该仔细阅读指南。 – Sukhito 2014-10-08 10:56:26