Javascript 余烬js:#每个显示子对象内容
在“sectionfeed”模型中,我将section作为belongTo。我想打印#中每个部分的内容,如下所示。它不起作用 如何在ember js中使用#each打印子对象的内容 模板Javascript 余烬js:#每个显示子对象内容,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,在“sectionfeed”模型中,我将section作为belongTo。我想打印#中每个部分的内容,如下所示。它不起作用 如何在ember js中使用#each打印子对象的内容 模板 {{#each sectionfeed in model.sectionfeeds}} <tr> <td> {{#link-to 'section' sectionfeed.s
{{#each sectionfeed in model.sectionfeeds}}
<tr>
<td> {{#link-to 'section' sectionfeed.section}}{{sectionfeed.id}}{{/link-to}} </td>
<td> {{sectionfeed.section.name}} </td> <-- Not getting printed
<td> {{fromNow sectionfeed.section.modifiedAt}} </td>
<td> {{fromNow sectionfeed.section.updatedAt}} </td>
<td> {{fromNow sectionfeed.section.liverpooledAt}} </td>
<td>
<button class="btn btn-primary btn-sm" {{action 'remove_section_feed' sectionfeed}}>Remove</button>
</td>
</tr>
{{ else }}
<tr>
<td colspan="5">
No Section found.
</td>
</tr>
{{/each}}
分段馈电模型
/*global Ember*/
Backoffice.Sectionfeed = DS.Model.extend({
sectionDefinitionID: DS.attr('string'),
sections:DS.belongsTo('section', {async: false}),
feedDefinitionID: DS.attr('string')
});
DS.RESTAdapter.reopen({
ajaxOptions: function(url, type, hash) {
hash = hash || {};
if (type === 'PUT') {
hash.data = hash.data || {};
hash.data['_method'] = type;
type = 'DELETE';
}
return this._super(url, type, hash);
}
});
剖面模型
/*global Ember*/
Backoffice.Section = DS.Model.extend({
// Section
name: DS.attr('string'),
icon: DS.attr('string'),
channelDefinitionID: DS.attr('string'),
liverpooledAt: DS.attr('date'),
// DataModel
createdAt: DS.attr('date'),
modifiedAt: DS.attr('date'),
// Cover Item
appleTouchIconURL: DS.attr('string'),
coverImageURL: DS.attr('string'),
tintColor: DS.attr('string'),
tintColorStyle: function () {
return 'background-color:' + this.get("tintColor") + ';';
}.property('tintColor'),
fontColor: DS.attr('string'),
fontColorStyle: function () {
return 'color:' + this.get("fontColor") + ';';
}.property('fontColor')
});
// probably should be mixed-in...
Backoffice.Section.reopen({
attributes: function () {
var model = this;
return Ember.keys(this.get('data')).map(function (key) {
return Em.Object.create({ model: model, key: key, valueBinding: 'model.' + key });
});
}.property()
});
余烬数据期望相关项在响应中位于单独的对象中。您需要实现嵌入的记录mixin,这样才能工作。()
/*global Ember*/
Backoffice.Section = DS.Model.extend({
// Section
name: DS.attr('string'),
icon: DS.attr('string'),
channelDefinitionID: DS.attr('string'),
liverpooledAt: DS.attr('date'),
// DataModel
createdAt: DS.attr('date'),
modifiedAt: DS.attr('date'),
// Cover Item
appleTouchIconURL: DS.attr('string'),
coverImageURL: DS.attr('string'),
tintColor: DS.attr('string'),
tintColorStyle: function () {
return 'background-color:' + this.get("tintColor") + ';';
}.property('tintColor'),
fontColor: DS.attr('string'),
fontColorStyle: function () {
return 'color:' + this.get("fontColor") + ';';
}.property('fontColor')
});
// probably should be mixed-in...
Backoffice.Section.reopen({
attributes: function () {
var model = this;
return Ember.keys(this.get('data')).map(function (key) {
return Em.Object.create({ model: model, key: key, valueBinding: 'model.' + key });
});
}.property()
});