使用javascript将数组转换为对象

时间:2014-11-07 18:55:35

标签: javascript jquery

我想构建一个如下图所示的结构

enter image description here

但我需要一些帮助,看看我做了多远(不要担心名字,问题就是数组)

enter image description here

我尝试了我在此thread中看到的解决方案,将数组转换为对象但是没有成功,就像您在下图中看到的那样。

enter image description here

我的代码

    for (index = 0; index < result.length; index++) {
        if (result[index].Parent_Id == 0) {

            // Remove all white spaces from my Text.
            var nome = result[index].Texto.replace(/ /g, '');

            // Add a new component.
            newMenu[nome] = {
                name: result[index].Texto,
                type: "item"
            };
        }
    }

    self.tree_data.push(newMenu);
    self.treeDataSource2 = new DataSourceTree({ data: self.tree_data });

如何进行第一张图片的结构?第一张图片中的_data是一个对象。

**

0 个答案:

没有答案
相关问题