2014-01-06 37 views
2

前言:我是新來的燼。使用餘燼數據和sails.js獲取空記錄

我在sails.js中設置了一個節點服務器,我在前端使用了ember。在我的路線文件我有以下幾點:

App.ApplicationRoute = Ember.Route.extend({ 
    model: function(){ 
     if(window.sessionStorage.getItem('current_user_id')){ 
      App.CurrentUser = window.sessionStorage.getItem('current_user_id'); 
      this.store.find('user', App.CurrentUser); 
      this.store.find('list', App.CurrentUser); 
     } 
    } 
}); 

原本應該屬於當前用戶,這樣,當用戶去#/lists/index所有的名單都已經加載的列表來預加載。

這是當我打電話#/lists/:id

{ 
    "lists": [ 
    { 
     "name": "popcicle", 
     "user_id": 1, 
     "createdAt": "2013-12-31T05:26:39.970Z", 
     "updatedAt": "2013-12-31T05:26:39.970Z", 
     "id": 48 
    }, 
    { 
     "name": "happy dance", 
     "user_id": 1, 
     "createdAt": "2013-12-31T05:28:51.220Z", 
     "updatedAt": "2013-12-31T05:28:51.220Z", 
     "id": 49 
    }, 
    { 
     "name": "something", 
     "user_id": 1, 
     "createdAt": "2013-12-31T05:34:53.616Z", 
     "updatedAt": "2013-12-31T05:34:53.616Z", 
     "id": 50 
    } 
    ] 
} 

然而,當我在Chrome中打開餘燼檢查並進入數據服務器的響應 - > App.List它顯示了4個項目:

Id Name 
1 
48 popcicle 
49 happy dance 
50 something 

打破我的觀點,因爲名字是undefined

TL/DR我要麼需要知道w^hy ember數據有這個空白列表以及如何擺脫它,或者如何在我的視圖中執行條件迭代,以便未定義的名稱不會中斷我的應用程序。

這裏是我的視圖代碼櫃面這是有幫助的:

<script type="text/x-handlebars" data-template-name="lists"> 
    <div class="left-nav"> 
     {{partial "listNav"}} 
    </div> 
    {{outlet}} 
</script> 

<script type="text/x-handlebars" data-template-name="_listNav"> 
    <h4> Lists </h4> 
    <div class="column-span2 left-nav"> 
     <ul> 
      {{#each list}} 
      <li> 
       {{name}} 
      </li> 
      {{/each}} 
     </ul> 
     {{#link-to "lists.new"}}Create List{{/link-to}} 
    </div> 
</script> 

回答

1

,我注意到有幾件事情:

+1

所以我使用的應用程序路由器,因爲這是預加載數據,如果已經有一個會話的用戶。所以用戶登錄葉子然後回來,如果他們的會話仍然活着,我想重新加載他們的所有列表,即使他們不在列表頁面上。另外,'/ lists /:id'確實指向'/ user /:id/lists',因爲列表屬於用戶。 – Ryan