2012-02-23 5 views
1

Google지도를 볼 수 있으며지도를 표시하여 다른 개체에서 바인딩 할 수 있습니다. 문제는 내가 didInsertElement에있는지도 만 인스턴스화 할 수 있기 때문에 (div가 아직 렌더링되지 않았기 때문에 직접 인스턴스화하지 못할 수도 있습니다.)지도의 실제 값에 액세스 할 수 없으며 항상 null을 반환합니다.ember.js보기에서 속성에 액세스 할 수 없습니다.

Places = Ember.Application.create(); 
Places.MapView = Ember.View.extend({ 
    tagName : 'div',  
    map : null,    
    didInsertElement : function() { 
     this._super(); 
     this.set('map', new google.maps.Map($('#map').get(0), { 
      mapTypeId: google.maps.MapTypeId.ROADMAP, 
     center: new google.maps.LatLng(-33.8665433,151.1956316), 
     zoom: 15 
     })); 
     this.get('map'); // Returns the value of the map OK 
    } 
}); 

Places.searchController = Ember.Object.create({ 
    mapBinding: 'Places.MapView.map' // Doesn't work 
} 

여기 템플릿의 :

여기 내 코드의

<script type="text/x-handlebars"> 
{{#view Places.MapView id="map"}}{{/view}}   
</script> 

내가 MapView 내에서 다른 속성을 설정하면 직접 내가 아무 문제 그것에 바인딩이 없습니다. 이 문제를 해결하는 방법에 대한 아이디어가 있습니까? 에서

답변

5

내 컨트롤러에서 일반적으로 뷰 개체가 아니라 "모델"개체에 바인딩됩니다.

지도를 다른 개체로 설정해보세요.

Places = Ember.Application.create(); 

Places.MapData = Ember.Object.create({ 
    map: null 
}); 

Places.MapView = Ember.View.extend({ 
    tagName : 'div',  
    map : null,    
    didInsertElement : function() { 
     this._super(); 
     Places.MapData.set('map', new google.maps.Map($('#map').get(0), { 
      mapTypeId: google.maps.MapTypeId.ROADMAP, 
     center: new google.maps.LatLng(-33.8665433,151.1956316), 
     zoom: 15 
     })); 
    } 
}); 

Places.searchController = Ember.Object.create({ 
    mapBinding: 'Places.MapData.map' 
}); 
1

당신의 searchController 당신이 MapView클래스의지도 속성에 바인딩된다. 클래스에는 map 속성이 없습니다. 클래스가 인스턴스화되고 didInsertElement이 실행되면 MapView인스턴스에지도 속성이 추가됩니다. 바인딩 작업을 수행하려면 클래스가 아닌 인스턴스화 된 뷰의 맵 특성에 바인딩해야합니다.

+0

내가 시도'Places.mapView = Places.MapView.create ({})'와'{{#view의 Places.mapView 아이디 =} "지도"} {{/보기}} 다음'하지만지도 화면에 나타나지 않습니다. – Johnny

관련 문제