Javascript 如何仅渲染环氧渲染函数内部的一个视图
我正在开发一个主干、木偶、环氧树脂、下划线程序,在渲染单个嵌套在Render()函数中的视图构造函数中的视图时遇到问题。此函数中还有3个其他视图,但是当调用构造函数时,我希望能够仅呈现CustomizationViewJavascript 如何仅渲染环氧渲染函数内部的一个视图,javascript,jquery,backbone.js,underscore.js,marionette,Javascript,Jquery,Backbone.js,Underscore.js,Marionette,我正在开发一个主干、木偶、环氧树脂、下划线程序,在渲染单个嵌套在Render()函数中的视图构造函数中的视图时遇到问题。此函数中还有3个其他视图,但是当调用构造函数时,我希望能够仅呈现CustomizationView render:function(){ this.$el.html(_.template(other_settings, {}, {variable:'args'})); this.ui_messages = new LIB.Mes
render:function(){
this.$el.html(_.template(other_settings, {}, {variable:'args'}));
this.ui_messages = new LIB.MessageCollectionView({
el:this.$('.messages ul'),
collection:this.model.get("_Messages"),
parent: this
});
this.ui_customizations = new LIB.CustomizationCollectionView({
el:this.$('.other-settings ul'),
collection:this.model.get("_Customizations")
});
this.ui_increments = new LIB.IncrementCollectionView({
el:this.$('.increments ul'),
collection:this.model.get("_Increments")
});
我有办法做到吗
这是为SettingsView调用视图构造函数并在CustomerView中呈现它的代码
render:function(){
//renders all of the settings from the settings inclusion variable
var data = this.viewModel.toJSON();
data.customer = this.model.toJSON();
this.$el.html(_.template(tmpl, data, {variable:'data'}));
this.ui_settings = new settings.SettingsView({
el: this.$('#vc-customer-settings'),
model: this.model.get("_Settings")
});
this.applyBindings();
}
这是settingsView构造函数内部的渲染函数。我可以注释掉我不想在CustomerView中看到的视图,它可以正常工作,但它会破坏程序的其余部分。调用settings.setingsView构造函数时,是否有任何方法可以直接获取CustomizationView模型的值?很明显,我想保留SettingsView,因为它包含了大量与CustomizationView一起需要的代码
render:function(){
this.$el.html(_.template(other_settings, {}, {variable:'args'}));
this.ui_messages = new LIB.MessageCollectionView({
el:this.$('.messages ul'),
collection:this.model.get("_Messages"),
parent: this
});
this.ui_customizations = new LIB.CustomizationCollectionView({
el:this.$('.other-settings ul'),
collection:this.model.get("_Customizations")
});
this.ui_increments = new LIB.IncrementCollectionView({
el:this.$('.increments ul'),
collection:this.model.get("_Increments")
});
我解决了这个问题。我只是创建了一个名为
adminRender()
的新构造函数,然后在其中使用一个新的html模板为this.$el.html(u.template())
调用了CustomizationView构造函数。然后,当SettingsView类对象在CustomerView内部实例化时,我针对当前工作目录进行了测试,并创建了一个三元语句来调用相应的呈现函数。看起来是这样的:
adminRender:function(){
this.$el.html(_.template(other_settings, {}, {variable: 'args'}));
this.ui_customizations = new LIB.CustomizationCollectionView({
el:this.$('.other-settings ul'),
collection:this.model.get("_Customizations")
});
this.listenToOnce(this.model, 'change:Keymap', this.initKeymap);
this.listenTo(this.model, 'keypressed', _.bind(this.replaceButton, this));
},
userRender:function(){
this.$el.html(_.template(tmpl, {}, {variable:'args'}));
this.ui_messages = new LIB.MessageCollectionView({
el:this.$('.messages ul'),
collection:this.model.get("_Messages"),
parent: this
});
this.ui_customizations = new LIB.CustomizationCollectionView({
el:this.$('.other-settings ul'),
collection:this.model.get("_Customizations")
});
this.ui_increments = new LIB.IncrementCollectionView({
el:this.$('.increments ul'),
collection:this.model.get("_Increments")
});
var pathName = window.location.pathname;
var pathName = "/admin/customers/new" ? view.adminRender() : view.userRender();
然后在SettingsView构造函数中,我将调用相应的呈现函数,如下所示:
adminRender:function(){
this.$el.html(_.template(other_settings, {}, {variable: 'args'}));
this.ui_customizations = new LIB.CustomizationCollectionView({
el:this.$('.other-settings ul'),
collection:this.model.get("_Customizations")
});
this.listenToOnce(this.model, 'change:Keymap', this.initKeymap);
this.listenTo(this.model, 'keypressed', _.bind(this.replaceButton, this));
},
userRender:function(){
this.$el.html(_.template(tmpl, {}, {variable:'args'}));
this.ui_messages = new LIB.MessageCollectionView({
el:this.$('.messages ul'),
collection:this.model.get("_Messages"),
parent: this
});
this.ui_customizations = new LIB.CustomizationCollectionView({
el:this.$('.other-settings ul'),
collection:this.model.get("_Customizations")
});
this.ui_increments = new LIB.IncrementCollectionView({
el:this.$('.increments ul'),
collection:this.model.get("_Increments")
});
var pathName = window.location.pathname;
var pathName = "/admin/customers/new" ? view.adminRender() : view.userRender();
现在它工作了!!!耶:)我解决了这个问题。我只是创建了一个名为
adminRender()
的新构造函数,然后在其中使用一个新的html模板为this.$el.html(u.template())
调用了CustomizationView构造函数。然后,当SettingsView类对象在CustomerView内部实例化时,我针对当前工作目录进行了测试,并创建了一个三元语句来调用相应的呈现函数。看起来是这样的:
adminRender:function(){
this.$el.html(_.template(other_settings, {}, {variable: 'args'}));
this.ui_customizations = new LIB.CustomizationCollectionView({
el:this.$('.other-settings ul'),
collection:this.model.get("_Customizations")
});
this.listenToOnce(this.model, 'change:Keymap', this.initKeymap);
this.listenTo(this.model, 'keypressed', _.bind(this.replaceButton, this));
},
userRender:function(){
this.$el.html(_.template(tmpl, {}, {variable:'args'}));
this.ui_messages = new LIB.MessageCollectionView({
el:this.$('.messages ul'),
collection:this.model.get("_Messages"),
parent: this
});
this.ui_customizations = new LIB.CustomizationCollectionView({
el:this.$('.other-settings ul'),
collection:this.model.get("_Customizations")
});
this.ui_increments = new LIB.IncrementCollectionView({
el:this.$('.increments ul'),
collection:this.model.get("_Increments")
});
var pathName = window.location.pathname;
var pathName = "/admin/customers/new" ? view.adminRender() : view.userRender();
然后在SettingsView构造函数中,我将调用相应的呈现函数,如下所示:
adminRender:function(){
this.$el.html(_.template(other_settings, {}, {variable: 'args'}));
this.ui_customizations = new LIB.CustomizationCollectionView({
el:this.$('.other-settings ul'),
collection:this.model.get("_Customizations")
});
this.listenToOnce(this.model, 'change:Keymap', this.initKeymap);
this.listenTo(this.model, 'keypressed', _.bind(this.replaceButton, this));
},
userRender:function(){
this.$el.html(_.template(tmpl, {}, {variable:'args'}));
this.ui_messages = new LIB.MessageCollectionView({
el:this.$('.messages ul'),
collection:this.model.get("_Messages"),
parent: this
});
this.ui_customizations = new LIB.CustomizationCollectionView({
el:this.$('.other-settings ul'),
collection:this.model.get("_Customizations")
});
this.ui_increments = new LIB.IncrementCollectionView({
el:this.$('.increments ul'),
collection:this.model.get("_Increments")
});
var pathName = window.location.pathname;
var pathName = "/admin/customers/new" ? view.adminRender() : view.userRender();
现在它工作了!!!耶:)请澄清这个问题,并将代码示例精简为最简单的“工作”代码段。从问题中删除所有其他不必要的代码。感谢您的帮助。非常感谢。不幸的是,为了呈现我试图呈现的视图,所有这些代码都是必需的。谢谢你指出这一点。:)请澄清问题,并将代码示例剥离为最简单的“工作”代码段。从问题中删除所有其他不必要的代码。感谢您的帮助。非常感谢。不幸的是,为了呈现我试图呈现的视图,所有这些代码都是必需的。谢谢你指出这一点。:)