Google지도 JSON API를 사용하여 지오 코딩을 구현하려고합니다.정적 객체의 변경 사항을 관찰하는 방법은 무엇입니까?
위치에 대한 모델을 만들었고 ObjectController, 모델에 비동기 지오 코딩 로직이 있습니다.
컨트롤러가 대부분의 업데이트 데이터를 반영하도록 모델의 변경 사항을 관찰하도록합니다.
나는 바인딩 및 관찰로 모두 노력하고있어 둘 다 작동하지 않습니다
App.Location = Ember.Object.extend({
formatted_address: null,
location: {
lat: null,
lng: null
}
})
App.Location.reopenClass({
geocoded: Ember.Object.create(),
geocode: function(address) {
$.ajax({
url: 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' + address,
dataType: 'json',
context: this,
success: function(response) {
App.Location.geocoded.set('response', response);
}
});
return this.geocoded;
}
});
App.LocationController = Ember.ObjectController.extend({
contentBinding: 'App.Location.geocoded',
testProperty: function() {
console.log('test');
}.property('content'),
testObserve: function() {
console.log('test');
}.observes('App.Location.geocoded')
});
편집 : observes('App.Location.geocoded.response')
로 변경 문제가 해결. 그것도 바인딩으로 작동 할 수 있습니까? 이 작업을 수행하는 더 좋은 방법이 있습니까?
어떻게 ObjectController와 Object를 연결합니까? ArrayController에 대해 pushObject를 사용할 수 있습니다. 어떻게 ObjectController의 내용을 업데이트하면 바인딩이있는 모든 내용이 업데이트됩니까? –
Euh, contentBinding : 'App.Location.geocoded'및 App.Location.set ('geocoded', Ember.Object.create ({response : response}))); 해야한다 : s –