Javascript 主干视图未初始化
我对主干js是一个绝对的初学者,并且一直在努力遵循。下面是我输入的最低代码Javascript 主干视图未初始化,javascript,jquery,backbone.js,underscore.js,Javascript,Jquery,Backbone.js,Underscore.js,我对主干js是一个绝对的初学者,并且一直在努力遵循。下面是我输入的最低代码 (function() { var MWLivePreview = {}; window.MWLivePreview = MWLivePreview; var MWTemplate = function(name) { return _.template($("#" + name + "-template").html()); } var log = function(logit) { consol
(function() {
var MWLivePreview = {};
window.MWLivePreview = MWLivePreview;
var MWTemplate = function(name) {
return _.template($("#" + name + "-template").html());
}
var log = function(logit) {
console.log(logit);
}
MWLivePreview.Index = Backbone.View.extend({
template: MWTemplate('live-preview'),
render: function() {
log(this.template(this));
this.$el.html(this.template(this));
return this;
}
});
MWLivePreview.Router = Backbone.Router.extend({
initialize: function(options) {
this.el = options.el
},
routes: {
"": "index"
},
index: function() {
var view = new MWLivePreview.Index();
this.el.empty();
this.el.append(view.render().el);
}
});
MWLivePreview.boot = function(container) {
container = $(container);
var router = new MWLivePreview.Router({el: container});
Backbone.history.start();
}
})()
下面的代码是我拥有的模板:
<script type="text/template" id="live-preview-template">
<div> We have got few templates</div>
</script>
我不确定哪里出了问题,但这会返回以下错误:
Uncaught TypeError: Object function (a){return new m(a)} has no method 'pick'
对可能出现的问题有什么想法或线索吗
编辑1:
删除主干.history.start()将停止给出错误,但视图中再次没有显示任何内容。
主干网唯一的硬依赖是非此即彼
但要注意匹配主干网所需的版本:在撰写本文时,主干网0.9.10的下划线为.js 1.4.3您知道发生错误的行号吗?您正在页面上加载下划线js吗?@Matt:堆栈跟踪中的最后一个端点位于第行
var view=new MWLivePreview.Index()代码>下划线js出现在页面上,并按其应该的顺序加载。Andom猜测:您的下划线.js版本与主干所需的版本不匹配(下划线1.4.3表示主干0.9.10)@nikoshr:Holy!修好了!非常感谢。
Uncaught TypeError: Object function (a){return new m(a)} has no method 'pick'