2013-05-07 60 views
1

我可能失去了一些東西容易或做錯了什麼麻煩,但我想這一點,並不能得到它火的功能...有延伸的骨幹視圖

var Home = Backbone.View.extend({ 
    indexAction: function() { 
     console.log('index'); 
    }, 
    render: function() { 
     console.log('render'); 
    } 
}); 
Home.indexAction(); 

我得到的是這樣的錯誤:

Uncaught TypeError: Object function(){return i.apply(this,arguments)} has no method 'indexAction'

回答

3

您創建了視圖類型但未創建實例。 您需要實例Home類型的視圖現在:

var h = new Home(); 
h.indexAction(); 

而且,它可能是更好的重命名爲家HomeView,讓你知道它的可實例化的視圖。

var HomeView = Backbone.View.extend({ 
    indexAction: function() { 
     console.log('index'); 
    }, 
    render: function() { 
     console.log('render'); 
    } 
}); 

var home = new HomeView(); 

​​

+0

其實只是嘗試這樣做,你公佈。其中一個facepalm時刻... – gokujou 2013-05-07 21:22:21