다음 코드를 사용하여 의류를 성공적으로로드했습니다. Chrome ember 관리자는 Garment와 관련 모델이 모두로드되었지만 관련 모델 (garment_colors)을 템플릿에 표시 할 수없는 것으로 나타났습니다.ember : 관련 모델이 크롬 검사기에 표시되지만 템플릿이 비어 있습니다.
정말 도움이 되겠습니까? 제대로 이름과 브랜드 표시와 같은 다른 속성 -
{{log garment_colors}}
는 하늘의 배열 Class {type: function, content: Array[0], store: Class, _changesToSync: OrderedSet, loadingRecordsCount: 0…}__ember1410723197678: "ember522"__ember_meta__: Object__nextSuper: undefined_changesToSync: OrderedSetcontent: Array[0]isLoaded: trueisPolymorphic: undefinedloadingRecordsCount: 0name: "garment_colors"owner: Classstore: ClasstoString: function() { return ret; }type: App.GarmentColor__proto__: Object ember-1.7.0.js:14463
var attr = DS.attr,
belongsTo = DS.belongsTo,
hasMany = DS.hasMany;
App.Garment = DS.Model.extend({
name: attr(),
brand: attr(),
description: attr(),
materials: attr(),
garment_colors: hasMany('garmentColor')
});
App.GarmentColor = DS.Model.extend({
name: attr(),
color: attr(),
garment: belongsTo('garment')
});
App.DesignerRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('garment',params.id);
},
setupController: function(controller, model) {
controller.set('content', model)
console.log(model);
},
});
내 JSON을
{
"garment":{
"id":2,
"name":"Ultra shirt",
"brand":"Gildan",
"description":"this is the description",
"materials":"5.6 oz. 50% preshrunk cotton, 50% polyester.",
"garment_color_ids":[
66,
67,
68
]
},
"garment_colors":[
{
"id":66,
"name":"Purple",
"color":"#4f237a"
},
{
"id":67,
"name":"Light Blue",
"color":"#89b4df"
},
{
"id":68,
"name":"Carolina Blue",
"color":"#91b0e6"
}
]
}
템플릿을 기록합니다. RESTAdapter
<script type="text/x-handlebars" data-template-name="designer">
{{outlet}}
<div id="product-details">
<h4>Style</h4>
<p id="name">{{name}}</p>
<p id="brand">{{brand}}</p>
<p id="description">{{description}}</p>
<p id="materials">{{materials}}</p>
<h4>Color</h4>
{{log garment_colors}}
<div id="color-list">
{{#each garment_colors}}
<label class="btn" style="background-color:{{color}}">
<input type="radio" name="color" value="{{name}}">
</label>
{{/each}}
</div>
</div>
</script>
당신이 JSON을 보여줍니다이 반환된다. 그리고 작동하지 않는 템플릿? – Kingpin2k
그냥 고마워! – user1465506