nestedSortable icon indicating copy to clipboard operation
nestedSortable copied to clipboard

Error when using toArray

Open TheSin- opened this issue 10 years ago • 2 comments

TypeError: null is not an object (evaluating 'parentItem')   '_recrusiveArray - jquery.mjs.nestedSortable.js:786'

I have a different attribute, I'm using data-id instead of id, but I tried using id to test and it still happened. data-id it an int, not sure if that is an issue? My root element is data-id: 1, so i set options for rootID: 1, but same error with or without it.

again am I just doing something wrong or is this a bug? I'm new to this plugin and still trying to work things out a little.

TheSin- avatar Dec 22 '15 17:12 TheSin-

After reading the code, I see now that the item id (or id attribute) NEEDS to be key[=-_]id, I didn't not find this in the doc at all and I was just setting it to id. so data-id="1", this causes a the error, I had to change to data-id="idontcare_1" which is ugly. To that end changing expression to some that does not return an array of 3 items would also break it. This doesn't seem like a great fix.

I'd recommend setting a default expression to /.+[=-_](.+)/ so it's only returning one item which is the id. that way other can just override the expression to return /(.*)/ for like in my case and chang the code to expect only one, so parentItem[0] instead of parentItem[2].

Anyhow I hope the helps other and I wish I didn't have to ugly up my html to make this work, but at least it's working now ;) I'll leave this open for other and incase you want to fix this in the future.

TheSin- avatar Dec 23 '15 17:12 TheSin-

Yes kind of a pain, you need to set the li element's id to be 'text_123' instead of '123'. Tacking on this comment so people can search for the console error I received and easily find this thread:

jquery.mjs.nestedSortable.js?ver=2.1a:784 Uncaught TypeError: Cannot read property '2' of null

austingray avatar May 25 '16 20:05 austingray