2

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

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

我 Console.logged 集合和列结果上面的异常发生在我的自定义单元格上。我认为这是因为它没有列属性:

在此处输入图像描述

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

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

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

4

1 回答 1

1

阅读文档看起来应该是

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

代替

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

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

于 2014-12-05T23:27:05.530 回答