Home - bigktmbig/MyExperienceAlgorithm GitHub Wiki
Welcome to the MyExperienceAlgorithm wiki!
- Get group object has same value to array from available array:
var arr_regular = [
{name: 'MO', value: "0900 - 1700"},
{name: 'TU', value: "0900 - 1700"},
{name: 'WE', value: "1000 - 1800"},
{name: 'TH', value: "1100-1730"},
{name: 'FR', value: "1000 - 1800"},
];
var arr_result = [];
for (var k = 0; k < arr_regular.length; k++) {
if(arr_regular[k].value && arr_regular[k].value != '') {
arr_result.push({list: arr_regular[k].name, value: arr_regular[k].value});
var idx_res = arr_result.length-1;
for (var h = k+1; h < arr_regular.length; h++) {
if(arr_regular[k].value == arr_regular[h].value) {
arr_result[idx_res].list += "," +arr_regular[h].name;
arr_regular.splice(h, 1);
}
}
}
}
-array result:
arr_result = [
{list: "MO,TU", value: "0900 - 1700"},
{list: "WE,FR", value: "1000 - 1800"},
{list: "TH", value: "1100 - 1730"}]
- create tree folder
-
var items = [
-
{id: 1, parentId: '', documents: [{id: 1}, {id: 2}]},
-
{id: 2, parentId: 1, documents: [{id: 1}, {id: 2}]},
-
{id: 3, parentId: 1, documents: [{id: 1}, {id: 2}]},
-
{id: 4, parentId: 2, documents: [{id: 2}]},
-
{id: 5, parentId: 2, documents: [{id: 1}, {id: 2}]},
-
{id: 6, parentId: 4, documents: [{id: 1}, {id: 2}]},
-
{id: 7, parentId: '', documents: [{id: 1}, {id: 2}]},
-
{id: 8, parentId: 5, documents: [{id: 2}]},
-
{id: 9, parentId: 1, documents: [{id: 1}, {id: 2}]}
-
];
-
function create_tree_folder(items) {
-
var map = {}
-
for (var i = 0; i < items.length; i++)
-
{
-
items[i].nodes = [];
-
items[i].count_document = items[i].documents.length
-
map[items[i].id] = items[i];
-
}
-
var newArray = [];
-
for (var id in map)
-
{
-
var item = map[id];
-
var parent = map[item.parentId];
-
if (parent) {
-
parent.nodes = parent.nodes || null;
-
parent.nodes.push(item);
-
}
-
else
-
{
-
item.nodes = item.nodes||null;
-
item.check_parentFolder = 1;
-
newArray.push(item);
-
}
-
}
-
$scope.data = newArray;
-
}