gpt4 book ai didi

javascript - 背景网格未附加我的自定义单元格

转载 作者:行者123 更新时间:2023-11-30 05:31:00 25 4
gpt4 key购买 nike

你好,我正在尝试将我创建的自定义类型的单元格附加到我的背景网格实例,但我不断收到以下错误:

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

我对集合和列进行了 Console.logged,结果发现上述异常发生在我的自定义单元格上。我认为是因为它没有列属性:

enter image description here

这是我的自定义单元格的样子:

  return QuestionCell.extend({

distractors: ['-', 't', 'f'],
template: 'gradescreen/table/mc',
render: function () {
var $val_td, view = this, correct_td = '',
current_state = view.model.get('responses').stateModel.get('state'),
correct_answer = '', selected = '-', select = '', pos, key_length;
view.current_response = view.getCurrentResponse(view.model);
if (view.current_response.get('response').prefix) {
selected = view.current_response.get(
'response'
).prefix === 'a' ? 't':'f';
}
if (view.question_meta.get('correct_prefix') ===
view.current_response.get(
'response').prefix) {
correct_td = ' correct_td';
}
$val_td = $('<td class="response_td' + correct_td + '" />');
app.fetchTemplate(view.template, function (tmpl) {
$val_td.html(tmpl({cid: view.cid, q_number: view.question_number}));
key_length = _.keys(view.question_meta.get('answers')).length;
for (pos = 0; pos <= key_length; pos++) {
var prefix = view.distractors[pos];
correct_answer =
prefix === view.question_meta.get('correct_prefix') ?
'correct_response':'';

select = selected === prefix ? 'selected="true"':'';
$('#answer_options_' + view.cid, $val_td).append(
'<option class="' + correct_answer + '" ' + select + ' >' +
prefix + '</option>');
}
if (current_state > 2) {
$('#answer_options_' + view.cid, $val_td).prop('disabled', true);
}
//view.bindEvents($val_td);
});
this.el = $val_td;
return this;
}
});
});

它是从我称为 QuestionCell 的单元格扩展而来的,它是从 Backgrid.Cell 扩展而来的,并且只包含默认属性和方法。

这就是我将单元格传递到背景网格的方式。

var grid, columns = [];

_.each(questions, function (question, position) {
if (question.get('type') === 'tf')
{
columns.push({
name: 'responses[0]',
label: 'Q-' + (position + 1),
cell: TFCell.extend({
question_meta : question,
question_number: position + 1,
group_id: view.group_id
})
});
}
else
{
//this last one isn't getting rendered for some reason.
columns.push({
label: 'Q-' + (position + 1),
cell: Backgrid.SelectCell.extend({
optionValues: [
['-', '-'], ['a', 'a'], ['b', 'b'],
['c', 'c'], ['d', 'd']
]
})
});
}
});
grid = new Backgrid.Grid({
columns: columns,
collection: view.model.get('student_responses')
});
$('#Student_Grid').append(grid.render().$el);

请帮忙。我怎样才能得到这个得到渲染。非常感谢

最佳答案

阅读文档看起来应该是

$('#Student_Grid').append(grid.render().el);

代替

$('#Student_Grid').append(grid.render().$el);

$el 看起来像一个函数,其中 el 是您要附加的节点对象。

关于javascript - 背景网格未附加我的自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27089761/

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