2013-11-23 23 views
0

我正在Rails和Ember.js中創建一個應用程序。我有以下幾點:Ember.js返回相同的模型

型號/ post.js

App.Post = DS.Model.extend({ 
    title: DS.attr('string'), 
    param: DS.attr('string') 
}); 

路線/ posts.js

App.PostsIndexRoute = Em.Route.extend({ 
    model: function() { 
    return this.store.findQuery('post'); 
    } 
}); 

// Esto hace falta? 
App.PostsShowRoute = Em.Route.extend({ 
    serialize: function(model) { 
    return { 
     post_id: model.get('param') 
    }; 
    } 
}); 

router.js

App.Router.reopen({ 
    location: 'history' 
}); 

App.Router.map(function() { 
    this.resource('posts', function() { 
    return this.route('show', { 
     path: '/:post_id' 
    }); 
    }); 
}); 

store.js

App.Store = DS.Store.extend({ 
    adapter: DS.RESTAdapter.reopen({ 
    namespace: 'api' 
    }) 
}); 

模板/ posts.hbs

{{outlet}} 

模板/職位/ index.hbs

<ul> 
    {{#each controller}} 
    <li>{{#linkTo "posts.show" this}}{{title}}{{/linkTo}}</li> 
    {{/each}} 
</ul> 

當我訪問本地主機:3000 /職位 我得到的職位列表,我的數據庫中有7個員額,在這個視圖中,ember.js顯示7(li)元素,但是具有最後的post元素。

我的數據庫有:POST1,POS2,post3,post4,post5,post6,post7 視圖顯示:post7,post7,post7,post7,post7,post7,post7

任何想法?

+0

你可以重現這個問題的小提琴嗎? –

+0

@MárcioRodriguesCorreaJúnior我正在使用此代碼:https://github.com/heartsentwined/ember-auth-rails-demo – ie8888

回答

0

我已經在models/post.js中添加了一個字段作爲id,所以帖子將是唯一的。這解決了我的問題。謝謝。

相關問題