ember 프레임 워크를 처음 사용하고 Ember 데이터에 액세스하는 데 문제가 있거나 의심 스럽습니다. 데모 목적으로 ember-cli와 ember-cli-mirage를 사용하고 있습니다.Ember : 컨트롤러/템플릿에서 모델 데이터에 액세스 할 수 없습니다.
config.js
export default function() {
this.get('/newcontracts', function(db, request) {
return {
data:[{
"type": "newcontracts",
"id": 1,
"attributes": {
"department-type": ["Legal", "Sales"],
"agreement-type": ["Service Agreement", "Purchase"],
"renewal-type": ["One time", "None"]
}
}]
}
});
엠버 스토어
export default Model.extend({
"type": "",
"department-type": attr(""),
"agreement-type": attr(""),
"renewal-type": attr("")
});
라우터
export default Ember.Route.extend({
model: function(){
console.log(this.get('store').findAll('newcontract')) // outputs ember class
return this.get('store').findAll('newcontract');
});
컨트롤러
export default Ember.Controller.extend({
details: Ember.computed('model', function() {
return this.store.peekRecord('new-contract', 1) // --> outputs ember class
//console.log(this.store.peekRecord('new-contract', 1).get('department-type)) ---> desired output(array)
})
departmentDetails: Ember.computed('model', function() {
this.details.get('department-type') ; ///error
})
});
는
{{log "model" details}} --> ember class
{{log "model" model}} --> ember class
{{log "model" model.department-type}} --> undefined
나는 그런 departmentDetails에 액세스 할 수 없습니다 템플릿? details 속성에서 주석 처리 된 행을 사용하면 원하는 데이터를 얻습니다. 상점과 별도로 각 데이터를 가져와야합니까? 또한 모델에 값을 기록하면 Ember 클래스가 제공됩니다.
는 심지어 템플릿 파일에, 나는 제대로 엠버 크롬 관리자에서 데이터를 가져 오는 등 model.department 형의 값
을 얻을 수 없습니다. Fyi, ember 2.5.1을 사용 중입니다. 친절하게 도와주세요.
당신의 모델은 타입 필드가있는 것의 뒤에있는 생각이다. JsonApi 어댑터를 사용하고 있습니까? 또한 귀하의 속성은 배열, 법률 ... 판매 ... 당신은 배열처럼 소비하고 싶어합니까? 몇 가지 팁을 제공 할 수는 있지만 부서 유형을 소비하는 방법에 대해 확신 할 수는 없습니다 ... 선택하십시오. –
변환을 지정하지 않으려면'attr ("")'이 아니라'atr()'을 사용해야합니다. 또한 departementDetails에서'this.get ('details')'을 할 필요가있다. – locks
모델 및 세부 정보는 모두 emer enumerables이므로 열거하여 데이터를 가져올 수 있습니다. 참조 http://stackoverflow.com/questions/37380384/get-data-from-emberjs-store-find/37408910#37408910 – kumkanillam