2016-06-25 3 views
1

익숙한 문제가 남아 있지만 혼자 해결할 수 없습니다. 그래서이 문제를 제거하도록 도와주세요. 잡히지 않은 TypeError :보기가 생성자가 아닙니다.

내보기 코드 :

var LayoutView = Backbone.View.extend({ 
    initialize: function() { 
    var self = this; 
    $.get('resources/html/layout.html', function(data) { 
     self.template = _.template(data); 
     self.render(); 
    }); 
    }, 
    render: function() { 
    var self = this; 
    $(self.el).html(self.template(self.model.toJSON())); 
    } 
}); 

내 렌더링 코드 :

$(document).ready(function() { 
    var LayoutView= new LayoutView({ 
     el:'#wrapper', 
     model:{} 
    }); 
}); 

내 예외 :

Uncaught TypeError: LayoutView is not a constructor 

답변

2

코드는해야한다 :

$(document).ready(function() { 
    var layoutView= new LayoutView({ 
    //--^---this 
    el:'#wrapper', 
    model:{} 
    }); 
}); 

같은 이름의 로컬 변수 선언이 원래 생성자를 숨기고 있기 때문입니다.

관련 문제