0

I wish to save the values from the input boxes in a dynamically created form but I´m having some trouble constructing the object that is to put into the IndexedDB objestStore. I need something like this:

[{"name": "box1 value", "last name": "box2 value", "age": "box3 value"},{"name": "box4 value", "last name": "box5 value", "age": "box6 value"}]

propriety names have to stay the same (equal to the indexes in the objectStore), only the values change.

The code:

var rows = document.getElementById('myTable').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
for (i = 0; i < rows.length; i++) {
    var boxes = rows.getElementsByClassName('input');
    for (i = 0; i < boxes.length; i++) {

       objectStore.put('values');

    };  
};

I'm trying JSON.stringify(); but I'm not getting it to work... Any ideas?

4

1 回答 1

1

我认为最好的做法是: - 为同一属性的所有输入字段赋予相同的名称属性 - 为每一行检索这些输入字段的值 - 构造对象 - 保存对象。

在伪代码中:

for each (row in rows){
  var obj = {};
  obj.name = row.getElementByName('name').value;
  obj.lastname = row.getElementByName('lastname').value;
  obj.age = row.getElementByName('age').value;

  objectStore.put(obj)
}
于 2012-10-18T09:13:15.020 回答