Is there any way in angular to create a hash map like structure

Developer52

I have a parent named domain and we can add multiple child beneath it and under every child we can add multiple sub child. I want to create a structure like this

enter image description here

I want to add a subchild under The business domain selected. It is working fine for the first element but when I add a subchild under any other Business domain selected It adds all the subchild created like this:

enter image description here

This is my service method where I am storing the subchild list:

app.factory('DomainNameService',['$q', function($q) {
var childSubDomainName=[];
     setBusSubDomain:function(val,busDomain){//In val I am getting the business 
//domain selected and in busDomain I am getting the name entered in name field
              if(childSubDomainName.length<1){
                childSubDomainName.push(busDomain);
            }
            else  {
                for(var i=0;i<childSubDomainName.length;i++){
                    var index = childSubDomainName[i].name.indexOf(busDomain.name);//Added this for unique name check
                }
                if(index==-1){//If the name is unique then i allow it to add to childSubDomainName
//Here I want to implement a logic that busDomain gets add only to the parent selected but I am not getting how to do this
                        childSubDomainName.push(busDomain);
                }
                else
                 this.error = 'Name already in use';
                }
    },
}
      

I am getting this type of structure for childSubDomainName

enter image description here

Can any one please suggest me how to do this. I have tried many things but it didn't worked.

koustubh

The looping construct you are using for inserting the objects in the heirarchy should involve the checking as to where exactly the child needs to inserted. This will involve two condition checks: 1. for the parent name 2. for the child existing under that parent object. 3. if both the above conditions matches only then the sub child should be inserted in the respective parent child heirarchy.

The heirarchy can be maintained in the follwing structure

[
    {
        "parentid": "id",
        "parentName": "name1",
        "children": [
            {
                "childid": "c_id1",
                "childname": "cn1",
                "subchild": [
                    {
                        "sbid": "id",
                        "sbname": "name"
                    },
                    {
                        "sbid": "id",
                        "sbname": "name"
                    }
                ]
            },
            {
                "childid": "c_id2",
                "childname": "cn2",
                "subchild": [
                    {
                        "sbid": "id",
                        "sbname": "name"
                    },
                    {
                        "sbid": "id",
                        "sbname": "name"
                    }
                ]
            }
        ]
    },
    {
        "parentid": "id",
        "parentName": "name1",
        "children": [
            {
                "childid": "c_id1",
                "childname": "cn1",
                "subchild": [
                    {
                        "sbid": "id",
                        "sbname": "name"
                    },
                    {
                        "sbid": "id",
                        "sbname": "name"
                    }
                ]
            },
            {
                "childid": "c_id2",
                "childname": "cn2",
                "subchild": [
                    {
                        "sbid": "id",
                        "sbname": "name"
                    },
                    {
                        "sbid": "id",
                        "sbname": "name"
                    }
                ]
            }
        ]
    } 
]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Any way to stream a map like "(k,v)" instead of working with (entry)?

From Dev

Is there any way to create video-like animation with javascript ?

From Dev

Is there any way to create bash like aliases in windows (powershell or cmd)?

From Dev

is there any way to create a common method to Email (Like:- Contact us in app)

From Dev

Stata- Is there a way to store data like Python's dictionary or a hash map?

From Dev

Faster way to create structure

From Dev

How to create recursive tree-like data structure in java using Map<String, T>?

From Dev

Create a hash from a map result

From Dev

Is there any way to unjs (like uncss)

From Dev

Is there a contiguously stored hash map data structure?

From Dev

tbb concurrent hash map as a member of structure

From Dev

Slick way to transform this data structure hash of hashes?

From Dev

Is there any HyperLogLog like structure for multiple multisets?

From Dev

Is there any way to create some codes which compiler will generate some another code like below?

From Dev

Is there a shorthand way to create a Map?

From Dev

Create hash structure from .each loop rails

From Dev

Is there any easy way to reverse this hash function?

From Dev

Create hash-of-hashes using structure of the default hash

From Dev

Is there a way to create swift frameworks like this?

From Dev

Is there any way to debug a certain data structure?

From Dev

Is there any way to avoid a conditional structure in this case?

From Dev

Javascript create object with data structure like this

From Dev

Create a tree like structure in html/css/javascript

From Dev

How to create a treeview like structure in Nstableview for OSX?

From Dev

Is it possible to create a JSON structure that looks like this

From Dev

Is there any way to create migrations in beego?

From Dev

Is there any way to create diagram for localdb?

From Dev

hash map with arraylist and create new arraylist out of it

From Dev

Any better way to execute something like this?

Related Related

  1. 1

    Any way to stream a map like "(k,v)" instead of working with (entry)?

  2. 2

    Is there any way to create video-like animation with javascript ?

  3. 3

    Is there any way to create bash like aliases in windows (powershell or cmd)?

  4. 4

    is there any way to create a common method to Email (Like:- Contact us in app)

  5. 5

    Stata- Is there a way to store data like Python's dictionary or a hash map?

  6. 6

    Faster way to create structure

  7. 7

    How to create recursive tree-like data structure in java using Map<String, T>?

  8. 8

    Create a hash from a map result

  9. 9

    Is there any way to unjs (like uncss)

  10. 10

    Is there a contiguously stored hash map data structure?

  11. 11

    tbb concurrent hash map as a member of structure

  12. 12

    Slick way to transform this data structure hash of hashes?

  13. 13

    Is there any HyperLogLog like structure for multiple multisets?

  14. 14

    Is there any way to create some codes which compiler will generate some another code like below?

  15. 15

    Is there a shorthand way to create a Map?

  16. 16

    Create hash structure from .each loop rails

  17. 17

    Is there any easy way to reverse this hash function?

  18. 18

    Create hash-of-hashes using structure of the default hash

  19. 19

    Is there a way to create swift frameworks like this?

  20. 20

    Is there any way to debug a certain data structure?

  21. 21

    Is there any way to avoid a conditional structure in this case?

  22. 22

    Javascript create object with data structure like this

  23. 23

    Create a tree like structure in html/css/javascript

  24. 24

    How to create a treeview like structure in Nstableview for OSX?

  25. 25

    Is it possible to create a JSON structure that looks like this

  26. 26

    Is there any way to create migrations in beego?

  27. 27

    Is there any way to create diagram for localdb?

  28. 28

    hash map with arraylist and create new arraylist out of it

  29. 29

    Any better way to execute something like this?

HotTag

Archive