Ember 2.7에서는 모델 이있는 Person
클래스가 Address
있다고 가정 city:DS.attr()
합니다 (유일한 속성 이라고 가정 ).
app / models / 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')}`;
});
Employee
에서 상속 Person
과 (고용처럼, 은퇴, 해고 등) 상태 필드를 추가
app / models / employee.js
import DS from 'ember-data';
import Person from '../models/person';
export default Person.extend({
status: DS.attr(),
statusCode: DS.attr(),
});
를 표시하는 구성 요소 Employees
에서 다음과 같이됩니다.
app / templates / components / employee-list.hbs
{{#each employees as |employee|}}
<div>
<h2>{{employee.fullName}}</h2>
<p>Home Base : [city]</p>
<p>Status : {{employee.status}}</p>
</div>
{{/each}}
템플릿이 주소 모델에서이 사람의 도시를 표시 할 수 있도록 EmberJS의 주소 Employee
(예 :이 ' Person
') 를 가져 오는 방법은 무엇입니까 ?
{{employee.address.city}}
필요한 핸들 바 코드입니다.
{{#each employees as |employee|}}
<div>
<h2>{{employee.fullName}}</h2>
<p>Home Base : {{employee.address.city}}</p>
<p>Status : {{employee.status}}</p>
</div>
{{/each}}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다