Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    New Coder
    Join Date
    Jul 2013
    Posts
    48
    Thanks
    9
    Thanked 1 Time in 1 Post
    Thank you for quick respons and for present a variety of solutions. I use recursion from your code and implemented with ExtJS.

  2. #17
    New Coder
    Join Date
    Jul 2013
    Posts
    48
    Thanks
    9
    Thanked 1 Time in 1 Post
    hi can you explain to me some part of your code :
    Code:
     obj[a].names= obj.names + (obj[a]["name"] ? "/" + obj[a]["name"]:"");
        recurseIt(obj[a]);
       }else{
        if(a == "name")selPath.add(new Option(obj[a],obj["names"]))

  3. #18
    New Coder
    Join Date
    Jul 2013
    Posts
    48
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by DaveyErwin View Post
    here I assume a different
    meaning for "path" ...

    Code:
     
       
       obj[a].names= obj.names + (obj[a]["name"] ? "/" + obj[a]["name"]:"");
        recurseIt(obj[a]);
       }else{
        if(a == "name")selPath.add(new Option(obj[a],obj["names"]))
       }
          }
    Can you explain t ome , what is happend here. I dont understand it. and this '?' what it do ?

  4. #19
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    You should be the one explaining what it is you really want instead of us assuming and guessing. Posting a sample "path" will help.

    Btw, the ? is a ternary operator which is a shorthand for if-else statement. Google for it for more info.

  5. #20
    New Coder
    Join Date
    Jul 2013
    Posts
    48
    Thanks
    9
    Thanked 1 Time in 1 Post
    http://pastebin.com/XxBKkY81
    Here is one of solution that has posted.
    Recursion is ok. Just has to be ExtJS comboBox, in 'store' has to be names from tree json, and has to be listeners who looks wich name from combobox is selected and in a text field show us the path to chosen one.

  6. #21
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    I don't know ExtJS so I had to take a look at their documentation to know how ExtJS combobox is done.

    One of the ways to specify the store array option is this (which is what you need in this case):

    Code:
    store: [
       [optionValue, optionText],
       [optionValue, optionText],
       [optionValue, optionText],
       //...and so on...
    ]
    So I tweaked DaveyErwin's code to extract the correct array format from the json data.

    Code:
    [
        ['/Planning', 'Planning'],
        ['/Planning/Investigate', 'Investigate'],
        ['/Planning/Assign Resources', 'Assign Resources'],
        //...and so on
    ]
    Here it is:

    Code:
    <div id="combobox"></div>
    <textarea id="path"></textarea>
    Code:
    var data = [{
        "name": "Planning",
        "id": 1,
        "parentId": 994423,
        "children": [{
            "name": "Investigate",
            "id": 11,
            "parentId": 1
        }, {
            "name": "Assign resources",
            "id": 12,
            "parentId": 1
        }, {
            "name": "Gather documents",
            "id": 13,
            "parentId": 1
        }, {
            "name": "Report to management",
            "id": 17,
            "parentId": 1,
            "children": [{
                "name": "Implementation Phase 1",
                "id": 4,
                "parentId": 17,
                "children": [{
                    "name": "Preparation work",
                    "id": 34,
                    "parentId": 4
                }, {
                    "name": "Evaluate chipsets",
                    "id": 14,
                    "parentId": 4
                }, {
                    "name": "Choose technology suite",
                    "id": 16,
                    "parentId": 4
                }, {
                    "name": "Build prototype",
                    "id": 15,
                    "parentId": 4,
                    "children": [{
                        "name": "Step 1",
                        "id": 20,
                        "parentId": 15
                    }, {
                        "name": "Step 2",
                        "id": 19,
                        "parentId": 15
                    }, {
                        "name": "Step 3",
                        "id": 18,
                        "parentId": 15
                    }, {
                        "name": "Follow up with customer",
                        "id": 21,
                        "parentId": 15,
                        "children": [{
                            "name": "Customer approval",
                            "id": 5,
                            "parentId": 21
                        }, {
                            "name": "Implementation Phase 2",
                            "id": 6,
                            "parentId": 21,
                            "children": [{
                                "name": "Task 3",
                                "id": 25,
                                "parentId": 6
                            }, {
                                "name": "Task 2",
                                "id": 26,
                                "parentId": 6
                            }, {
                                "name": "Task 1",
                                "id": 27,
                                "parentId": 6,
                                "children": [{
                                    "name": "Production phase 1",
                                    "id": 8,
                                    "parentId": 27,
                                    "children": [{
                                        "name": "Assemble",
                                        "id": 22,
                                        "parentId": 8
                                    }, {
                                        "name": "Load SW",
                                        "id": 23,
                                        "parentId": 8
                                    }, {
                                        "name": "Basic testing (inc some test)",
                                        "id": 24,
                                        "parentId": 8,
                                        "children": [{
                                            "name": "Customer approval 2",
                                            "id": 10,
                                            "parentId": 24
                                        }]
                                    }]
                                }]
                            }]
                        }]
                    }]
                }]
            }]
        }]
    }, {
        "name": "Final testing",
        "id": 9,
        "parentId": 123321
    }, {
        "name": "Delivery",
        "id": 7,
        "parentId": 654321
    }];
    
    var storeArr = [];
    data.names = "";
    (function recurseIt(obj) {
        for (var a in obj) {
            if (typeof obj[a] == "object") {
                obj[a].names = obj.names + (obj[a]["name"] ? "/" + obj[a]["name"] : "");
                recurseIt(obj[a]);
            } else {
                if (a == "name") {
                  storeArr.push([obj["names"], obj[a]]);
                }
            }
        }
    })(data);
    
    
    Ext.create('Ext.form.field.ComboBox', { 
        fieldLabel: 'Choose One',
        store: storeArr,
        renderTo: Ext.getDom('combobox'),
        listeners: {
            change: function(field, newValue, oldValue) {
                document.getElementById('path').value = field.value;
            }
        }
    });


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •