2011-10-30 11 views
8

이것은 정말 혼란스럽고, 저는 바보 같다고 생각합니다.하지만 제가 할 수있는대로 조사하고 수행했습니다. 뷰를 선언하고 jasmine으로 BDD 테스트를 실행할 때마다 항상 "정의되지 않은 함수가 아닙니다"를 반환합니다.백본보기 - 정의되지 않았습니다.

TypeError: undefined is not a function 
    at [object Object].make (http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:29:37) 
    at [object Object]._ensureElement (http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:30:270) 
    at [object Object].<anonymous> (http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:28:127) 
    at new <anonymous> (http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:32:136) 
    at [object Object].<anonymous> (http://localhost/gmap_api/public/test/spec/specs.js:62:21) 
    at [object Object].execute (http://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1001:15) 
    at [object Object].next_ (http://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1790:31) 
    at [object Object].start (http://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1743:8) 
    at [object Object].execute (http://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:2070:14) 
    at [object Object].next_ (http://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1790:31) 
+0

"보기를 선언 한 다음 새보기를 선언하는"것이 확실하지 않습니다. 하나의 LocationView와 두 번째 LocationView를 인스턴스화하고 있습니까? 첫 번째는 괜찮지 만 두 번째 것은 아닙니다. 또는'새로운 LocationView ({model : this.location})는 작동하지만'new LocationView();는하지 않습니까? –

+0

@muistooshort : 나쁜 영어로 유감스럽게 생각합니다. 그것은 그것이 내가 선언 했음에도 불구하고 LocationView가 매번 정의되지 않는다는 것을 알려주는 것을 의미합니까? – nXqd

답변

18

자바 스크립트 파일을 잘못된 순서로 포함 시켰을 때 비슷한 문제가있었습니다. 다음과 같이 가져 오기 :

jQuery.js 
Underscore.js 
Backbone.js 
YourCode.js 

그렇다면이 예외가 발생하는 행을 게시하십시오.

+0

내 문제가 해결되지 않습니다. 지금 재스민을 사용하여 프로젝트를 다시 만듭니다.하지만이 여기에 가장 좋은 대답을 보입니다. 감사합니다 – nXqd

+1

당신은 백본의 개발 버전을 포함해야하며, backbone이 뷰의 HTML 요소를 만들려고 할 때 오류가 발생합니다. http://documentcloud.github.com/backbone/docs/backbone.html#section-117 다음과 같은 경우에 $를 사용할 수없는 것 같습니다. 당신은 당신의 도움에 대한 – dira

+0

도움을 주셔서 감사합니다. – nXqd

1

는 당신에게보기의 정의는 확실 : 나는 자스민이 코드를 실행하면

this.view = new LocationView({model: this.location}); 
this.view = new LocationView(); 
// neither of these ones work. 

이 오류입니다 : 이것은이 내가 그것을 선언하는 방법입니다 코드

window.LocationView = Backbone.View.extend({ 
    initialize: function() { 
     // create new marker first 
     this.marker = new google.maps.Marker({ 
      title: this.model.get('name'), 
      draggable: true, 
      animation: google.maps.Animation.DROP, 
      position: new google.maps.LatLng(this.model.get('lat'), this.model.get('long')), // give the position here 
     }); 

     // bind events 
     this.model.bind('change', this.render, this); 
    }, 
    render: function() { 
     this.marker.setTitle(this.model.get("name")); 
     this.marker.setPosition(new google.maps.LatLng(this.model.get('lat'), this.model.get('long'))); 
    }, 
}); 

입니다 전에 초기화 코드? 별도의 파일에있는 경우 먼저 View의 정의가 실행 되었습니까?

+0

새 모델의 정의를 선언하고 호출 할 때. 그것은 잘 작동합니다 : ( – nXqd

관련 문제