Search code examples
jsondhtmlxuser-data

DHTMLX tree does not set userdata automatically


this is JSON response from the server:

{
    "id" : "0",
    "child" : 0,
    "text" : "a",
    "userdata" : [],
    "item" : [{
            "id" : "1",
            "text" : "b",
            "item" : null,
            "child" : 1,
            "userdata" : [{
                    "name" : "data-code",
                    "value" : "23"
                }, {
                    "name" : "data-title",
                    "value" : "title1"
                }
            ]
        }
    ]
}

but dhtmlx tree plugin does not set user data and when i call tree.getUserData(1, 'data-code') it returns undefined. how can i solve this problem?


Solution

  • Try to replace "value" property with "content" in userdata definition:

    "userdata" : [{
                    "name" : "data-code",
                    "content" : "23"
                }, {
                    "name" : "data-title",
                    "content" : "title1"
                }
            ]