2013-11-20 37 views
0

我想在Ember中做一個旋轉木馬滑塊,但我已經堆疊,因爲我不能讓Ember獲取我的圖像。在這裏我的代碼:Ember不顯示獲取模型

應用:

window.ArtRank = Ember.Application.create(); 

ArtRank.ApplicationAdapter = DS.FixtureAdapter.extend(); 

路由器:

ArtRank.Router.map(function(){ 
     this.resource('index', {path: '/'}, function() { 
      this.resource("home", {path: '/'}, function() { 
       this.resource("photo", {path: '/photo'}); 
      }); 
      this.resource('categories', { path: "/categories" }); 
      this.resource('profile', { path: "/profile" }); 
     }); 
    }); 


ArtRank.PhotoRoute = Ember.Route.extend({ 
    model: function() { 
     return this.store.find('photo'); 
    } 
}); 

型號: 指數頁眉和頁腳和{{內:

ArtRank.Photo = DS.Model.extend({ 
    imageTitle: DS.attr('string'), 
    imageUrl: DS.attr('string') 
}); 

ArtRank.Photo.FIXTURES = [ 
    { 
     id: 1, 
     imageTitle: 'Learn Ember.js', 
     imageUrl: 'http://getbootstrap.com/2.3.2/assets/img/bootstrap-mdo-sfmoma-01.jpg' 
    }, 
    { 
     id: 2, 
     imageTitle: '...', 
     imageUrl: 'http://getbootstrap.com/2.3.2/assets/img/bootstrap-mdo-sfmoma-01.jpg' 
    }, 
    { 
     id: 3, 
     imageTtitle: 'Profit!', 
     imageUrl: 'http://getbootstrap.com/2.3.2/assets/img/bootstrap-mdo-sfmoma-01.jpg' 
    } 
]; 

我的模板被由outlet}}

Outelet通話home.hbs即:{{局部照片}}

home.hbs呈現photo.hbs那就是:

<div class="photos-wrap"> 
     <h1>{{ imageTitle }}</h1> 

     <div class="photoItem"> 
       <img id="photoItem" {{bind-attr src="imageUrl"}} /> 
     </div> 
</div> 

任何建議非常感謝!

回答

1

對於回答我自己的問題(所以它不會停留開放),它的工作原理每個東西很好,我只是不明白,你甲腎上腺素編輯去特定的路由器取數據。我認爲你可以從應用程序的任何地方抓取它們,但是當你在特定的應用程序中時,只會顯示它們。

0

你錯過了你的模板中的每一個,因爲你reoute定義的模型掛鉤的結果是一個數組

{{#each}} 
    <h1>{{ imageTitle }}</h1> 

    <div class="photoItem"> 
      <img id="photoItem" {{bind-attr src="imageUrl"}} /> 
    </div> 
    {{/each}} 

而且資源定義是不正確的恕我直言,二/路徑...嘗試像配置

this.resource('index', {path: '/'}, function() { 
     this.resource("home", {path: 'home'}, function() { 

好運

+0

謝謝你,是一個很好的觀點,但不幸的是,這並不是問題,因爲與Ember檢查員一起看,我根本沒有得到日期。我的ArtRankPhoto爲空:( –

+0

請嘗試更改資源定義:-) – Edu