2013-02-18 60 views
0

我是一個絕對的初級骨幹js,並一直試圖沿着this 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()停止給錯誤,但沒有再次在視圖中出現。

+0

你知道行號發生錯誤的地方?你是否在你的頁面上加載了下劃線j? – 2013-02-18 12:23:37

+0

@Matt:堆棧跟蹤中的最後一個端點在線 'var view = new MWLivePreview.Index();' 下劃線js位於頁面上並按照它的順序加載 – 2013-02-18 12:25:18

+3

隨機猜測:您的underscore.js版本與Backbone所要求的版本不一致(主幹0.9.10爲下劃線1.4.3) – nikoshr 2013-02-18 12:33:03

回答