0

I have 6 textboxes at the top of the screen that update an entire column(one textbox per column) based on any changes. I was selecting the columns based on their class (.l#). Here is the code (issues to follow):

function UpdateField() {
  var ctrl = this;
  var id = parseInt(ctrl.id.replace("item", ""), 10) - 1;
  var bound = [".l1", ".l7", ".l8", ".l9"];
  var fields = $(bound[id]);

  for (var i = 0; i < fields.length; i++)
  {
    fields[i].innerHTML = $(ctrl).val();
  }
};

which is bound to the keyup event for the text areas. Issues are:

1) initially fields.length was -1 as I didn't want to put data in the "add new 
   row" section at the bottom. However, when running it, I noticed the 
   final "real" record wasn't being populated. Also, when stepping through, I
   noticed that the "new row" field was before the "last row" field.
2) when doing it this way, it is purely superficial: if I double click the field,
   the real data hasn't been changed.

so in the grand scheme of things, I know that I was doing it wrong. I'm assuming it involves updating the data and then forcing a render, but I'm not certain.

4

1 回答 1

2

想出了如何去做。以这种方式修改原始代码:

 function UpdateField() {
   var ctrl = this;
   var id = parseInt(ctrl.id.replace("item", ""), 10) - 1;
   var bound = ['title1', 'title2', 'title3', 'title4'];
   var field = bound[id];

  for (var i = 0; i < dataView.getLength(); i++)
  {
      var item = dataView.getItem(i);
      item[field] = $(ctrl).val();
      dataView.updateItem(i, item);
  }
  grid.invalidate();
};

我有 6 个文本框(item1-item6)“绑定”到字段,因为如果我更改文本框中的数据,它会更新所有行,并且添加的任何新行也具有此数据。

可以通过这种方式解释这两个问题的部分:

1)要解决这个问题,尽管它仍然是一个表示修复而不是对底层数据的真正更新,如果它附加了活动类,可以强制它忽略。额外的工作,而不是朝着“真正”的方向前进(掩盖领域)。

2) 最初的实现很明显(尽管我当时只能通过 Chrome 开发工具弄清楚我可以修改)它只是更新 div 的内容,而不是实际与下面的数据交互。看起来不错,如果提交的话,也许可以从 item1-item6 框中提取数据来代替列,但如果有人试图修改单元格,他们将再次查看真实数据。

于 2013-10-09T15:25:59.057 回答