0

我是骨干 js 的绝对初学者,并且一直在尝试遵循这个 GIT repo的思路。下面是我输入的最低限度的代码。

(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()停止给出错误,但视图中也没有出现任何内容。

4

1 回答 1

1

来自http://backbonejs.org/

Backbone 唯一的硬依赖是Underscore.jsLo-Dash

但要注意与 Backbone 所需的版本相匹配:在撰写本文时,Backbone 0.9.10 的 underscore.js 1.4.3

于 2013-02-18T12:44:19.017 回答