我是Ember的新手,我需要帮助才能了解如何使用多个模型显示数据。 我正在使用夹具适配器,还有我的模型和夹具
用户模型
App.User = DS.Model.extend({
name: DS.attr(),
phone: DS.attr(),
comment: DS.attr(),
city: DS.belongsTo('city'),
type: DS.belongsTo('type')
});
App.User.FIXTURES = [
{
id: 1,
name: 'Roger Brown',
phone: '+1 (218) 12345678',
comment: 'Lorem ispum dolor sit amet in voluptate fugiat nulla pariatur.',
city: 3,
type: 1
},
{
id: 2,
name: 'Ashton Black',
phone: '+7 (920) 12345678',
comment: 'Lorem ispum dolor sit amet in voluptate fugiat nulla pariatur.',
city: 4,
type: 2
}
];
城市模型
App.City = DS.Model.extend({
name: DS.attr(),
user: DS.hasMany('user', {async: true})
});
App.City.FIXTURES = [
{
id: 3,
name: 'Lisbon',
user: [1]
},
{
id: 4,
name: 'Moscow',
user: [2]
}
];
输入型号
App.Type = DS.Model.extend({
name: DS.attr(),
user: DS.hasMany('user', {async: true})
});
App.Type.FIXTURES = [
{
id: 1,
name: 'individual',
user: [1]
},
{
id: 2,
name: 'legal entity',
user: [2]
}
];
我的用户路线
App.UserRoute = Ember.Route.extend({
model: function(params){
return this.store.find('user', params.user_id);
}
});
用户模板
<div class="col-sm-12">
<div class="panel form-horizontal">
<div class="panel-heading">
<span class="panel-title">User View</span>
</div>
<div class="panel-body">
<div class="form-group">
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<p>{{name}}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Phone</label>
<div class="col-sm-10">
<p>{{phone}}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Comment</label>
<div class="col-sm-10">
<p>{{comment}}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">City</label>
<div class="col-sm-10">
<p>
{{city}}
</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Type</label>
<div class="col-sm-10">
<p>{{type}}</p>
</div>
</div>
<div class="form-group">
<button {{action 'deleteUser'}}>Delete</button>
</div>
</div>
</div>
</div>
{{outlet}}
当我试图显示用户细节时,我会得到类似的东西
City <App.City:ember385:3>
Type <App.Type:ember388:1>
请帮助了解如何获取此字段的名称! 非常感谢你:微笑:
答案 0 :(得分:0)
您的City
和Type
对象是Ember类型 - 您需要显示您感兴趣的属性,如下所示:
{{city.name}}
{{type.name}}