我有一個視圖擴展了外部庫(我們稱之爲ExtLib)也是基於骨幹牽線木偶。基本上這個lib是共享行爲的常見視圖的包裝(例如DetailsView,FormView等)。所以,讓我們說我有這樣的事情:如何窺視延伸與Jasmine的外部庫的Marionette視圖
MyApp.module('Views', function(Views, App, Backbone, Marionette, $, _) {
Views.MyDetailsView = Marionette.ExtLib.DetailsView.extend({
options: {
fields: [
// ...
],
myFunction: function() {
// ...
}
}
});
});
在我的茉莉花測試,我稱之爲創建MyDetailsView實例的控制器方法。
it('does what it should', function() {
// ...
controller.showDetails();
// my expectations
});
實際上,控制器中的方法只是創建視圖並將其呈現(在佈局的區域中)。
showDetails: function(story) {
var container = new App.Layouts.DetailsLayout();
var myDetailsView = new App.Views.MyDetailsView({
model: story
});
container.details.show(storyDetailsView);
}
最後,這裏是我得到的錯誤:
TypeError: Cannot read property 'length' of undefined
at eval (eval at <anonymous> (http://localhost:8080/myapp/js/lib/underscore/underscore-min.js?_debugResources=y&n=1354890505115:30:350), <anonymous>:17:35)
at c (http://localhost:8080/myapp/js/lib/underscore/underscore-min.js?_debugResources=y&n=1354890505115:30:430)
at Object.Backbone.Marionette.Renderer.render (http://localhost:8080/myapp/js/backbone-app/conf/renderer.js?_debugResources=y&n=1354890505115:9:17)
at r.ItemView.r.View.extend.render (http://localhost:8080/myapp/js/lib/backbone/backbone.marionette.min.js?_debugResources=y&n=1354890505115:13:4719)
at Backbone.Marionette.ExtLib.ExtLib.DetailsView.Backbone.Marionette.View.extend.renderFieldView (http://localhost:8080/myapp/js/lib/backbone.marionette.extlib.min.js?_debugResources=y&n=1354890505115:395:14)
// etc...
我覺得現在的問題是,茉莉不知道EXTLIB的。我如何偵察renderFieldView以避免錯誤?
在此先感謝,一如既往。