0
다음 코드는 작동하고 필요한 모든 작업을 수행하지만 매우 깨끗한 것은 아닙니다. 누군가가 내 작업을 수행하는 더 좋은 방법을 지적 할 수 있다면 정말 좋을 것입니다. 나는 그것이 더 좋을 수 있다고 생각하는 이유를 설명하기 위해 코드에 주석을 달았다.서버 데이터에서 모델을 정의하는 더 좋은 방법이 있습니까?
이 코드는 내 BuildingRoute의 모델을 정의하고 서버의 데이터로 업데이트합니다.
App.BuildingRoute = Ember.Route.extend({
buildingData : { // Can't I just create the object once my data comes,
name: '', // is it necessary to initialize this object?
addr1: '',
addr2: ''
},
model: function() {
this.getNodeInfo(); // should I be calling the function to access the server here?
return this.buildingData;
},
getNodeInfo: function(){
var _this = this;
var req = {
callback: nodeDataCB,
something: {
method: 'getNode',
uid: 'getNodeData',
nodeId: gVars.node
}
}
Server.getData(req);
function nodeDataCB(data){
console.log($.parseXML(data));
var attributes = $(data).find('attributes');
var addr1 = attributes.find('attr[n="disAddress1"]').html();
var addr2 = attributes.find('attr[n="disAddress2"]').html();
var name = $(data).find('name').text();
Ember.set(_this.buildingData, 'name', name); // must I set the value for each
Ember.set(_this.buildingData, 'addr1', addr1); // specifically, can't i just set
Ember.set(_this.buildingData, 'addr2', addr2); // the whole object at once?
}
}
});
엠버 데이터를 사용해야합니까?
놀랍습니다. 감사합니다. – sherlock