Ember 2.7 모델 상속-부모와 관련된 모델에서 가져온 템플릿의 데이터에 액세스하는 방법은 무엇입니까?

rmcsharry

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') 를 가져 오는 방법은 무엇입니까 ?

rmcsharry

{{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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관