gpt4 book ai didi

javascript - 在 View - Backbone 上的元素后面附加多个 View

转载 作者:行者123 更新时间:2023-11-28 18:58:39 25 4
gpt4 key购买 nike

   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);
}

我正在尝试在父 View 中存在的 div 之后附加多个 View

但是我收到错误 el is undefined,尽管我已经定义了 el

我的维度 View :

    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

enter image description here

最佳答案

目前,您的 DimensionsView 的渲染方法不返回任何内容,因此返回 undefined (默认),因此 dimensionsView.render().el 相当于 undefined.el,它会抛出错误。

您需要从 render 方法返回对 View 的引用,以便可以像 render().el 一样链接它

尝试

render: function () {
this.$el.html(dimensionsTemplate({ id: this.id, counter: this.counter }));
return this;
}

关于javascript - 在 View - Backbone 上的元素后面附加多个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33063580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com