Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动态创建树列表?_Javascript_Angularjs_Ionic Framework - Fatal编程技术网

Javascript 动态创建树列表?

Javascript 动态创建树列表?,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,我想在angular中创建一个树列表。我正在用电脑来做这件事。根据请求的结果,我已经创建了一些逻辑来创建列表 到目前为止,这就是我所拥有的: for (var i = 0; i < data.records.length; i++) { var l1_name = null; var l2_name = null; var l3_name = null; if (data.records[i].Product_Group_Name_L1__c) {

我想在angular中创建一个树列表。我正在用电脑来做这件事。根据请求的结果,我已经创建了一些逻辑来创建列表

到目前为止,这就是我所拥有的:

for (var i = 0; i < data.records.length; i++) {
    var l1_name = null;
    var l2_name = null;
    var l3_name = null;

    if (data.records[i].Product_Group_Name_L1__c) {
        var has = existProduct(data.records[i]);
        if (!has) {
            l1_name = data.records[i].Product_Group_Name_L1__c;
        }
    }

    if (data.records[i].Product_Group_Name_L2__c) {
        var has = existProduct(data.records[i]);
        if (!has) {
            l2_name = data.records[i].Product_Group_Name_L2__c;
        }
    } else {
        // so tem um
    }

    if (data.records[i].Product_Group_Name_L3__c) {
        var has = existProduct(data.records[i]);
        if (!has) {
            l3_name = data.records[i].Product_Group_Name_L3__c;
        }
    } else {

    }

    if (data.records[i].Product_Group_Name_L4__c) {
        var has = existProduct(data.records[i]);
        if (!has) {
            l4_name = data.records[i].Product_Group_Name_L4__c;
        }
    } else {
        var productName = data.records[i].Name;
    }

    vm.tasks.push({
        name: l1_name,
        tree: [{
            name: l2_name,
            tree: [{
                name: l3_name,
                tree: [{
                    name: productName
                }]
            }]
        }]
    });
}

var results = [];
var keys = {};

function existProduct(data) {
    var val = data.Product_Group_Name_L1__c;
    if (angular.isUndefined(keys[val])) {
        keys[val] = true;
        results.push(val);
        return true;
    } else {
        return false;
    }
}
在线示例()显示了如何通过
生成示例节点(obj,num)
创建动态数据,显示了可以根据需要修改树


也许您有范围处理问题?
[{
    Product_Group_Name_L1__c: "OX",
    Product_Group_Name_L2__c: "INT",
    Product_Group_Name_L3__c: "MASC",
    Product_Group_Name_L4__c: null,
    Name: "PROD",
    ..
}]