我正在尝试使用Backbone.js并且一直遵循Thomas Davis概述的“模块化”方法。
在尝试在另一个视图中“包含”视图时,我似乎陷入困境,如下所示:
SettingsView.js
define([
'jquery',
'underscore',
'backbone',
'text!templates/settings/settingsTemplate.html'
], function($, _, Backbone, settingsTemplate){
var SettingsView = Backbone.View.extend({
el: $("#interface"),
render: function() {
this.$el.html(settingsTemplate);
}
});
return SettingsView;
});
ScriptView.js
define([
'jquery',
'underscore',
'backbone',
'views/settings/SettingsView',
'models/script/ScriptModel',
'collections/scripts/ScriptsCollection',
'text!templates/script/scriptTemplate.html'
],
function($, _, Backbone, SettingsView, ScriptModel, ScriptsCollection, scriptTemplate) {
var ScriptView = Backbone.View.extend({
el : $("#container"),
render : function() {
this.$el.html(scriptTemplate);
//add the settings view
var settingsView = new SettingsView();
settingsView.render();
}
});
return ScriptView;
});
更新:我已设法解决了我刚刚意识到的错误,为什么会发生错误(参数错误 - DOH !!)
我不再收到错误,但我的'SettingsView'仍然没有出现。当我在“ScriptView.js”中控制登录时,我发现“el”未定义,所以我的想法是这就是问题所在......?
由于