我是脊椎骨js的绝对初学者,并一直试图遵循这个GIT回购的路线。下面是我输入的最起码的代码。
(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>我通过调用文档上的代码来连接整件事情
MWLivePreview.boot($("#asapatterns"));我不太清楚我哪里出了问题,但这会返回以下错误:
Uncaught TypeError: Object function (a){return new m(a)} has no method 'pick' 有什么可能出问题的想法或线索吗?
编辑1:
删除Backbone.history.start()会停止产生错误,但是视图中也不会出现任何错误。
发布于 2013-02-18 12:44:19
来自http://backbonejs.org/
主干的唯一硬依赖是Underscore.js或罗达什。
但是要小心匹配主干所需的版本:在编写本报告时,underscore.js 1.4.3用于主干0.9.10
https://stackoverflow.com/questions/14936202
复制相似问题