-1

I have an array representing groups, like this:

  • Company Name
  • IT
  • Finance
    • Global Finance
      • Financial Department
    • Tax and Co.

and I want to select a certain node (say Financial Department) and assign to a new array only it and its parents (Global Finance, Finance and Company name, which is not a problem since it's the static root node).

I am using angularjs (angular-ui-tree and angular-ui-tree-filter, if that helps) and can use jquery, 3rd party libraries etc.

Is there an easy way to achieve this? I thought about asking here, instead of using time on doing something someone may already have done.

Array Example:

$scope.groups = [{
        "id": 1,
        "title": "Company Name",
        "selected": "",
        "enabled": "",
        "CampaignId": "string",
        "TenantId": "string",
        "CompanyId": "string",
        "items": [{
            "id": 2,
            "title": "Board of Directors",
            "selected": "",
            "enabled": "",
            "CampaignId": "string",
            "TenantId": "string",
            "CompanyId": "string",
            "items": []
        }, {
            "id": 3,
            "title": "Finance",
            "selected": "",
            "enabled": "",
            "CampaignId": "string",
            "TenantId": "string",
            "CompanyId": "string",
            "items": [{
                "id": 4,
                "title": "Global Finance",
                "selected": "",
                "enabled": "",
                "CampaignId": "string",
                "TenantId": "string",
                "CompanyId": "string",
                "items": [{
                    "id": 5,
                    "title": "Financial department",
                    "selected": "",
                    "enabled": "",
                    "CampaignId": "string",
                    "TenantId": "string",
                    "CompanyId": "string",
                    "items": []
                }, {
                    "id": 6,
                    "title": "Region Asia Pacific",
                    "selected": "",
                    "enabled": "",
                    "CampaignId": "string",
                    "TenantId": "string",
                    "CompanyId": "string",
                    "items": []
                }]
            }, {
                "id": 7,
                "title": "Tax & Co.",
                "selected": "",
                "enabled": "",
                "CampaignId": "string",
                "TenantId": "string",
                "CompanyId": "string",
                "items": []
            }]
        }, {
            "id": 8,
            "title": "Sales",
            "selected": "",
            "enabled": "",
            "CampaignId": "string",
            "TenantId": "string",
            "CompanyId": "string",
            "items": []
        }, {
            "id": 9,
            "title": "Manufacturing",
            "selected": "",
            "enabled": "",
            "CampaignId": "string",
            "TenantId": "string",
            "CompanyId": "string",
            "items": []
        }
}];
Manuel Maestrini
  • 409
  • 6
  • 15

1 Answers1

0

never mind, I used another library called tree-model-js which allows me to traverse a tree, get the parents, and many other functionalities. That has given me all i need.

Manuel

Manuel Maestrini
  • 409
  • 6
  • 15