ember.js - EmberData - DIsplay belongsTo relationship in Handlebars Template -


i've got handlebars template displaying list of articles. each article has 2 prompts associated through belongsto relationship. information correctly coming server json:

{"article":[{"id":7,"prompt_one":{"content":"thing1"},"prompt_two":{"content":"thing2"}]} 

now i'm able render other data article okay, haven't been able data 1 of prompts render in handlebars template. thought simple as:

<p>{{prompt_one.content}}</p> 

but nothing shows , no errors displayed. what's proper way render associated models content?

you can 2 things:

  1. embedded records. if prompt objects embedded article's json need define them embedded (ember-data not support embedded objects).

    ds.restadapter.map('app.article',{     prompt:{         embedded:'always'     } })  app.article = ds.model.extend({     prompt: ds.belongsto(app.prompt,{embedded:'always'}), }); 
  2. custom object attribute. if want embed objects , not use belongsto relationship can register own ds.attr('object') type.

    ds.restadapter.registertransform('object', {   deserialize: function(serialized) {     return ember.isempty(serialized) ? {} : json.parse(serialized);   },   serialize: function(deserialized) {     return ember.isempty(deserialized) ? '' : json.stringify(deserialized);   } }); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -