這確實讓我困惑,我覺得我傻,但我已經搜查,已經做了一切我所能。 每當我聲明一個視圖並用茉莉花運行BDD測試時,它總是返回「未定義不是函數」。這是代碼骨幹觀點 - 沒有定義
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')));
},
});
這是我宣佈它:
this.view = new LocationView({model: this.location});
this.view = new LocationView();
// neither of these ones work.
這是錯誤,當我運行此代碼茉莉:
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)
我不確定「聲明視圖然後聲明新視圖」是什麼意思。你實例化一個LocationView,然後是第二個LocationView嗎?第一個很好,但第二個不是?或者'新的LocationView({model:this.location})'工作,但'新的LocationView();'不? –
@ muistooshort:對不起,我修好了。這意味着它會提示我LocationView不是每次都定義,儘管我聲明瞭它? – nXqd