addDimensions: function (order_id, counter) {
this.dimensionsView = new dimensionsView({ el: "#panel-boxes-" + order_id + "_" + counter, id: order_id, counter: counter });
$("#panel-boxes-" + order_id + "_1").append(this.dimensionsView.render().el);
}
我试图在父视图中存在div后附加多个视图
但我得到错误el未定义虽然我已经定义了el
我的尺寸视图:
var $ = jQuery = require('jquery'),
Backbone = require('backbone'),
Handlebars = require('handlebars'),
_ = require('underscore'),
messagesHandler = require('../../../libs/messages/messagesHandler'),
dimensionsTemplate = require("../../../templates/order/actions/Dimensions.html");
var DimensionsView = Backbone.View.extend({
tagName: "div",
initialize: function (options) {
this.id = options.id;
this.counter = options.counter;
},
render: function () {
this.$el.html(dimensionsTemplate({ id: this.id, counter: this.counter }));
}
});
module.exports = DimensionsView;
错误:
$("#panel-boxes-" + order_id + "_1").append(this.dimensionsView.render().el); //Error here
答案 0 :(得分:3)
目前,DimensionsView
的渲染方法不会返回任何内容,因此会返回undefined
(默认值),因此dimensionsView.render().el
与undefined.el
等效,导致错误。< / p>
您需要从render
方法返回对视图的引用,以便您可以将其链接为render().el
试
render: function () {
this.$el.html(dimensionsTemplate({ id: this.id, counter: this.counter }));
return this;
}