2013-07-21 41 views
0

我一直在尝试渲染数据在相同的视图,似乎不能得到正确的东西。我希望能够在地点展示广告网络上呈现每个地点的评分。Ember和Rails一对多关系

这是我得到的。

我已经尝试了不同的路线和不同的资源嵌套,以及在铁轨控制器中渲染不同的东西。我可以找回正确的评级哈希,但不知道如何显示它。

我假设在我的导轨控制器中出现了问题,或者我需要在把手视图中执行某些操作。我已经尝试了很多东西,所以我甚至没有发布我的铁轨东西。如果这个Ember的东西是正确的,那么使用车把和轨道控制器渲染它的正确方法是什么。

App.Router.reopen 
    location: 'history' 
    rootURL: '/' 

App.Router.map -> 
    @resource 'users', -> 
    @route 'new', 
@route 'edit', 
     path: '/:user_id/edit' 
    @route 'show', 
     path: '/:user_id' 
    @resource 'locations', -> 
    @route 'new', 
    @route 'show', 
     path: '/:location_id' 
    @resource 'ratings', -> 
    @route 'new', 
    @route 'show', 
     path: '/:ratings_id' 

App.Rating = DS.Model.extend(
    rating: DS.attr('string', defaultValue: "-0") 
    description: DS.attr('string', defaultValue: "No Description Provided") 
    location: DS.belongsTo("App.Location") 
) 

App.Location = DS.Model.extend(
    name: DS.attr('string', defaultValue: "") 
    address: DS.attr('string', defaultValue: "") 
    city: DS.attr('string', defaultValue: "") 
    state:DS.attr('string', defaultValue: "") 
    ratings: DS.hasMany('App.Rating') 
    fullAddress: (-> 
    "http://maps.google.com/?q=#{@get('address')},#{@get('city')},#{@get('state')}}" 
).property('address') 
) 


App.Store = DS.Store.extend(
    revision: 11 
    adapter: DS.RESTAdapter.create(mappings: 
    ratings: App.Rating 
) 
) 

回答

0

没有模板,路线或控制器很难分辨。

既然你有模型之间的关系,在你的模板中引用它的方式将是location.ratings其中位置将是#each中的变量。这工作得很好。如果您已经加载了收视率,您将可以立即访问它们。或者它会请求从服务器获得这些评级。

引用来自不同控制器的数据的另一个主要想法是使用needs API。

needs: 'foo', 
ratingsBinding: 'controllers.foo'