2013-01-23 34 views
0

如果我從指數到遊戲瀏覽,數據顯示,由於{{#linkTo}}的上下文,但如果我刷新網站,每次遊戲名稱不顯示。emberjs前4燼數據:無數據瀏覽器的刷新


編輯:這裏是一個 fiddle,但不幸的是小提琴版本與燈具適配器正常工作,甚至與肯的建議,從遊戲模板中刪除模型。


從/ API /遊戲返回的數據如下:

{ 
    "games":[ 
     { 
     "id":1, 
     "name":"First Game" 
     } 
    ] 
} 

和從/ API /遊戲/ 1

{ 
    "game": [ 
    { 
     "id": 1, 
     "name": "First Game" 
    } 
    ] 
} 
<script type="text/x-handlebars" data-template-name="application"> 
    {{outlet}} 
</script> 

<script type="text/x-handlebars" data-template-name="games"> 
    <ul>{{#each game in controller}} 
    <li>{{#linkTo 'game' game}}{{game.name}}{{/linkTo}}</li> 
    {{/each}}</ul> 
</script> 

<script type="text/x-handlebars" data-template-name="game"> 
    <h1>Name:{{model.name}}</h1> 
</script> 
<script type="text/javascript"> 
    App = Ember.Application.create(); 

    App.Game = DS.Model.extend({ 
    name: DS.attr('string') 
    }); 

    App.Store = DS.Store.extend({ 
    revision: 11, 
    adapter: DS.RESTAdapter.create({ 
     namespace: 'api' 
    }) 
    }); 

    App.GamesController = Ember.ArrayController.extend({ 
    content: [] 
    }); 

    App.GameController = Ember.ObjectController.extend({ 
    content: null 
    }); 

    App.Router.map(function(match) { 
    this.route("games", { path : "/" }); 
    this.route("game", { path : "/games/:game_id" }); 
    }); 

    App.GameRoute = Ember.Route.extend({ 
    model: function(params) { 
     return App.Game.find(params.game_id); 
    } 
    }); 

    App.GamesRoute = Ember.Route.extend({ 
    setupController: function(controller) { 
     controller.set('content', App.Game.find()); 
    } 
    }); 
</script> 

返回的數據有沒有人有想法?從你的遊戲模板

回答

0

刪除模型,試試這個,而不是

<script type="text/x-handlebars" data-template-name="game"> 
    <h1>Name:{{name}}</h1> 
</script> 

的jsfiddle你的代碼,看看問題出在哪裏

0

從我的服務器的單機遊戲的反應是錯誤的。我有一個單一的對象在其中的陣列,但我使用了對象控制器,所以我通過僅響應而修復了它。

{ 
    "game": { 
    "id": 1, 
    "name": "First Game" 
    } 
}