2
私は動的にツリーリストを作成したいと思います。私はion-tree-list pluginを使っています。私はすでに私の要求の結果を受けてリストを作成するためのロジックを作成しました。動的にツリーリストを作成しますか?
これまでのところ、これは私が持っているものです。
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;
}
}
私data.records
はこのようなものです:
[{
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",
..
}]
多分あなたは問題を扱っていますか? – fer