如何在javascript中循环遍历子对象?

17 浏览
0 Comments

如何在javascript中循环遍历子对象?

我在一个函数中有这段代码:

tableFields = tableFields.children;
for (item in tableFields) {
    // 做一些事情
}

根据tableFields的console.log,我得到了一个数组,正如我所假设的。循环中item的console.log返回undefined。我需要做什么来遍历tableFields并将每个对象插入表格中?

tableFields的console.log:

HTMLCollection[label, input, label, input 25, label, input, input, input Remove]
0
label
1
input
2
label
3
input 25
4
label
5
input
6
input
7 
input Remove
description[]
input
hours[]
input
invoice_number
input
getlength
8
rate[]
input 25
item
item()
iterator
iterator()
namedItem
namedItem()
__proto__
HTMLCollectionPrototype { item=item(), namedItem=namedItem(), iterator=iterator()}

以下是我到目前为止的整个代码部分:

$this->title("Test");
    $this->defaultMenu();
    $select = "";
    $names = Customer::getNames();
    foreach ($names as $id => $name) {
        $select .= '';
    }
    $form = '


    
    


    
    


    
    



    

'; if (!is_null($this->id)) { $form .= ''; } $form .= '
'; $this->component($form);

0