开发者

jstree get_json duplicating tree data

So I have a jstree that looks like this:

Root

-1

-2

--2.1

---2.1.1

----2.1.1.1 through 2.1.1.24 (as in 24 children under 2.1.1)

---2.1.2

----2.1.2.1 through 2.1.2.24 (as in 24 children under 2.1.1)

--2.2

-3

When I generate the json in order to stringify and send to the server (post user mucking around with it), before it gets sent to the server I can see that the post stringify json has duplicated a bunch of data. For instance, 2.1.1.1-24 gets duplicated twice under 2.1.1, and 2.1.1 (along with the double-duplication of 2.1.1.1-24) gets duplicated later in the string. The same goes for some other elements. 2.1.2 gets duplicated, but the data under it 2.1.2.1-开发者_开发问答24 doesn't get duped twice.

As in this is what I see in the string:

...

---2.1.1

----2.1.1.1 through 2.1.1.24 (as in 24 children under 2.1.1)

----2.1.1.1 through 2.1.1.24 (as in 24 children under 2.1.1)

(NOTE: twice for the 1-24 children)

Then that whole block above gets repeated again later in the string.

The 2.1.2 block likewise gets repeated twice. Of course once it gets to the server and I deserialize the string into objects its a real mess. Any ideas?

var v = jQuery.jstree._reference("#tree").get_json(-1);
var mytext = JSON.stringify(v);
alert(mytext);

I can see in the pop up all the duplicated data. It appears to be duplicating children under the higher level parent. Once I deserialize, I see that some of the instances of that duplicated data appears as a child of "Root" even though said data is grand-child/great grandchild. Under root, the only "children" should be 1, 2, & 3. Instead, I have 1, 2, 2.1, 2.1.1 (along with 2.1.1.1-24) 2.1.2 (but oddly not 2.1.2.1-24), 2.2 & 3.

PS - I've tested this in the latest versions of IE, Firefox, and Chrome.


Discovered the problem. My tree is being auto-generated from a database. I had left out part of the composite name I'm using for the "id" of the elements. Because of this "id" was not unique throughout the document. E.g. "Root" and 2.1.1 had the same "id" value, and that was why various elements got duplicated.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜