骨干观点 - 没有定义 [英] backbone view - is not defined
本文介绍了骨干观点 - 没有定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这真的让我困惑,我觉得我傻,但我已经搜查,已经做了一切我可以。
每当我宣布一个视图,并运行茉莉花BDD测试,它总是返回未定义是不是一个函数。这是code
window.LocationView = Backbone.View.extend({
初始化:功能(){
//首先创建新的标记
this.marker =新google.maps.Marker({
标题:this.model.get(名称),
拖动:真实,
动画:google.maps.Animation.DROP,
位置:新google.maps.LatLng(this.model.get('纬度'),this.model.get('长')),//在这里给位置
}); //绑定事件
this.model.bind('变',this.render,这一点);
},
渲染:功能(){
this.marker.setTitle(this.model.get(名字));
this.marker.setPosition(新google.maps.LatLng(this.model.get('纬度'),this.model.get(长)));
},
});
这是我宣布它是:
this.view =新LocationView({模式:this.location});
this.view =新LocationView();
//没有这些的工作。
这是错误,当我运行这个code茉莉花:
类型错误:未定义不是一个函数
在[目标对象]。使(http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:29:37)
在[对象的对象] ._ ensureElement(http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:30:270)
在[目标对象]<&匿名GT; (http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:28:127)
在新的<&匿名GT; (http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js:32:136)
在[目标对象]<&匿名GT; (HTTP://localhost/gmap_api/public/test/spec/specs.js:62:21)
在[目标对象] .execute(HTTP://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1001:15)
在[目标对象] .next_(HTTP://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1790:31)
在[目标对象]。开始(HTTP://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1743:8)
在[目标对象] .execute(HTTP://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:2070:14)
在[目标对象] .next_(HTTP://localhost/gmap_api/public/test/spec/jasmine/jasmine.js:1790:31)
解决方案
我有一个类似的问题时,我包括在错误的顺序我的JavaScript文件。导入它们像这样:
的jquery.js
Underscore.js
Backbone.js的
您code.js
如果这不是这样,那么在发布此异常发生时行了。
This really confuses me, I think I'm stupid but I've searched and have done whatever I could. Whenever I declare a view and run BDD test with jasmine, it always returns "undefined is not a function". This is code
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 is how I declared it :
this.view = new LocationView({model: this.location});
this.view = new LocationView();
// neither of these ones work.
This is the error when I run this code with jasmine:
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)
解决方案
I had a similar problem when I included my javascript files in the wrong order. Import them like so:
jQuery.js
Underscore.js
Backbone.js
YourCode.js
If that's not the case then post the line at which this exception occurs.
这篇关于骨干观点 - 没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文