add filterByLevel

pull/49/head
fateme 4 years ago
parent a80a2d1760
commit 5b9efa4291

@ -10,7 +10,8 @@ var CommingSoonArray = [
"blog-post", "blog-post",
"blog-setting", "blog-setting",
"client_export", "client_export",
"blog-videos" "blog-videos",
"service-specialInfo"
]; ];
const commingSoon = { const commingSoon = {
methods: { methods: {

@ -1,5 +1,7 @@
import Vue from 'vue'; import Vue from 'vue';
import '@Global/utils/common/Object';
// global Styles // global Styles
import "@riophae/vue-treeselect/dist/vue-treeselect.css";//for tree select import "@riophae/vue-treeselect/dist/vue-treeselect.css";//for tree select

@ -0,0 +1,42 @@
// Warn if overriding existing method
if(Array.prototype.equals)
console.warn("Overriding existing Array.prototype.equals. Possible causes: New API defines the method, there's a framework conflict or you've got double inclusions in your code.");
// attach the .equals method to Array's prototype to call it on any array
Array.prototype.equals = function (array) {
// if the other array is a falsy value, return
if (!array)
return false;
// compare lengths - can save a lot of time
if (this.length != array.length)
return false;
for (var i = 0, l=this.length; i < l; i++) {
// Check if we have nested arrays
if (this[i] instanceof Array && array[i] instanceof Array) {
// recurse into the nested arrays
if (!this[i].equals(array[i]))
return false;
}
else if (this[i] != array[i]) {
// Warning - two different object instances will never be equal: {x:20} != {x:20}
return false;
}
}
return true;
}
// Hide method from for-in loops
Object.defineProperty(Array.prototype, "equals", {enumerable: false});
Array.prototype.matchItems = function (array) {
// if the other array is a falsy value, return
if (!array)
return [];
return this.filter(item => array.includes(item));
}
// Hide method from for-in loops
Object.defineProperty(Array.prototype, "matchItems", {enumerable: false});

@ -287,6 +287,25 @@ const insertTreeArray = (
// }; // };
const filterByLevel = (list, level1) => {
let filteredList = [];
let level = parseInt(level1);
checkLevel(list);
function checkLevel(list, parentId = null, levelCounter = 1) {
list.map(item => {
if(item.parent_id == parentId) {
if(levelCounter == level) {
filteredList.push(item);
} else {
checkLevel(list, item.id, levelCounter + 1);
}
}
})
}
return filteredList;
}
export { export {
convertTreeToList, convertTreeToList,
insertTreeArray, insertTreeArray,
@ -295,5 +314,6 @@ export {
listSearchSelect, listSearchSelect,
convertListToTree, convertListToTree,
addIndexTreeToList, addIndexTreeToList,
addHierarchyToList addHierarchyToList,
filterByLevel
}; };

Loading…
Cancel
Save