我正在尝试使用Backbone渲染Bootstrap模式。我需要检查模板中的一些HTML元素(使用$('#tpl-create-details').html()
),并在渲染之前隐藏它们,但我遇到了一些问题。
display:none
,也不会隐藏元素。display:none
添加到元素中,但之后我不能使用相同的模板对象,因为它不会在页面上显示为一个Bootstrap模式,但是纯HTML。app.Views.CreateDetails = Backbone.View.extend({
initialize: function () {
var template = $('#tpl-create-details').html();
template = $(template);
this.collection.each(function (item) {
var customizingItem = item.toJSON();
var fieldId = customizingItem.name;
if (customizingItem.hidden) {
var field = template.find('input[name=' + fieldId + ']');
var field = $(field.get(0));
field.parent().parent().css('display', 'none');
}
}, this);
this.template = _.template(template.html());
},
render: function () {
var html = this.template();
this.$el.append(html);
return this;
}
});
app.Router = Backbone.Router.extend({
routes: {
'create': 'create'
},
create: function () {
var customizing = new app.Collections.Customizing();
customizing.fetch({
reset: true,
success: function (collection, response, options) {
var CreateDetailsView = new app.Views.CreateDetails({
collection: collection
});
$('#content').append(CreateDetailsView.render().$el);
var modalAdd = this.$('#modalDetail');
modalAdd.modal('show');
}
});
}
});