开发者

How can I select specific JSON attributes for jstree?

开发者 https://www.devze.com 2023-04-02 02:50 出处:网络
I have implemented a jstree which uses the json_data plugin to retrieve json data with ajax from a server. The json attributed for one node look like:

I have implemented a jstree which uses the json_data plugin to retrieve json data with ajax from a server. The json attributed for one node look like:

{"data":"1","uri":"http://www.abc.com/1"}

My problem now is, how can I save these attributes in the jstree nodes? I know that there's a "data" option looking like this:

"data" : function (n) {
            return { id : n.attr ? n.attr("i开发者_JS百科d") : 0 
         }; 

I'm relativley new to jquery and jstree and I don't know how I can use the data option to assign these attributed to the nodes. This is important because I have to get the JSON data from the tree after it was changed (using create, rename, remove, dnd operations) and therefore the JSON has to look like the one which was initially requested from the server through ajax.

Can somebody help me?

Have a nice day!


You create your json jsTree structure + data + all attributes on server side.

jsTree receives json and displays it. There might be some way how to tweak the data in javascript once you received it. Make it simple and do it on server side.

Below is bit of my server side script in ruby that creates json structure. Note that year, month etc are custom attributes.

hash_tmp = {
            "data" => dir,
            "attr" => {  "group" => group,
                         "build_name" => build_name,
                         "year" => year_tmp,
                         "month" => month_tmp,
                         "daytime" => daytime,
                         "action" => action,
                         "rel" => type,
                      },
            "state" => state,
            "children" => ""
            }
0

精彩评论

暂无评论...
验证码 换一张
取 消