저는 현재 로컬 컴퓨터에서 한동안 개발해온 응용 프로그램을 가지고 있습니다. 지금 서버 환경에 배치하고 템플릿을 백본보기에 삽입 할 때 jQuery의 .html() 함수 타이밍과 관련 있다고 생각되는 문제가 있습니다.Backbone.js jQuery 렌더링 타이밍 문제
코드로에서(중요한 부분)
가
<div id="map">map goes here</div>
mapView.js
01define(["models/mapModel",
"views/base/mapView"],function(MapModel, MapView){
var initialize = function(){
// Set up the application here
var mapModel, mapView;
dojo.ready(function(){
mapModel = new MapModel();
mapView = new MapView({
model : mapModel
});
$("#appRoot").html(mapView.render().el);
});
};
return {
initialize: initialize
};
});
ViewTemplate.html를 application.js
// 'viewTemplate' is being retrieved with dojo's define() method, // this is not the issue as it is working in many other places. initialize : function(){ var selectFeature = lang.hitch(this, this.getFeature); topic.subscribe("selectFeature", selectFeature); }, render : function(){ var tmpl = _.template(viewTemplate); this.$el.html(tmpl()); this.model.on("change:map", this.createLocator, this); //Create the map once everything is drawn $(document).ready($.proxy( function() { this.createMap(); }, this)); return this; }, createMap : function(){ console.log($('#appRoot').length); // returns 1 console.log($('#map').length); // returns 0 }
내 문제는 CreateMap 함수의 두 줄로 설명됩니다. #app가 render의 jQuery의 .html() 함수에 의해 삽입되는 동안 #appRoot는 index.html에 정적으로 정의됩니다. CreateMap()이 발생할 때까지 #map 요소가 삽입되지 않는 것 같습니다. 다시 말하지만, 이것은 localhost가 아닌 다른 컴퓨터에서 앱을 치는 경우에만 발생합니다.
감사 JP
'# map'에 대한 JQuery 호출 유효 범위를 시도해 보셨습니까? 나는. 'console.log (this. $ ('# map'). length); ' – mnoble01