brg*_*brg 14 ember.js ember-data
让我们说我的rails模型看起来像这样:
class SalesRelationship < ActiveRecord
end
Run Code Online (Sandbox Code Playgroud)
这是由crossSell继承的,如下所示:
class crossSell < SalesRelationship
end
Run Code Online (Sandbox Code Playgroud)
如何在ember-data中显示此继承关系.这是什么最好的做法:
App.salesRelationship = DS.Model.extend({
name: DS.attr('string')
});
Run Code Online (Sandbox Code Playgroud)
我可以像这样创建一个名为'crossSell'的子类
crossSell = App.salesRelationship({
productName: DS.attr('string')
});
Run Code Online (Sandbox Code Playgroud)
或者像这样
App.salesRelationship.crossSell = DS.Model.extend({
productName: DS.attr('string')
});
Run Code Online (Sandbox Code Playgroud)
Bra*_*est 13
非常接近,您可以扩展SalesRelationship.
App.CrossSell = App.SalesRelationship.extend({
productName: DS.attr('string')
})
Run Code Online (Sandbox Code Playgroud)
在Ember 2.7中,它可以像这样完成.假设你有一个Person类,并希望继承它以创建Employee一个状态字段(如雇用,退休,休假等)
应用程序/模型/ person.js
import DS from 'ember-data';
export default DS.Model.extend({
firstName: DS.attr(),
lastName: DS.attr(),
fullName: Ember.computed('firstName', 'lastName', function() {
return `${this.get('lastName')}, ${this.get('firstName')}`;
});
Run Code Online (Sandbox Code Playgroud)
应用程序/模型/ employee.js
import DS from 'ember-data';
import Person from './person';
export default Person.extend({
status: DS.attr(),
statusCode: DS.attr(),
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4019 次 |
| 最近记录: |