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:
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'}), });
custom object attribute. if want embed objects , not use
belongsto
relationship can register ownds.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
Post a Comment