0

This dynatree code. Generating auto generated ids.

$("#tree").dynatree({
selectMode:1,
generateIds:true
});   

These are all li ids of dynatree ul. all ids are autogenerated ids. here i am fetching all li ids to bind on drop event. i want all autogenerated ids in one go. i should not have to specify individual. i want dynamic. anyone.

 var obj = $("#dynatree-id-_3,#dynatree-id-_6,#dynatree-id-_7,#dynatree-id-_8,#dynatree-id-_9,#dynatree-id-_10,#dynatree-id-_11,#dynatree-id-_12,#dynatree-id-_13,#dynatree-id-_16,#dynatree-id-_17,#dynatree-id-_18,#dynatree-id-_19,#dynatree-id-_20,#dynatree-id-_21");
Paresh3489227
  • 845
  • 11
  • 22
  • Guys Thanks For your valuable answers. But i also need one Constraint. That it should fetch all ids of leaf nodes only. Can anyone explain – Paresh3489227 Apr 17 '14 at 05:42

4 Answers4

2

You can use attribute selectors:

var obj = $('[id^="dynatree"]');

The above code would get you items which has id started with dynatree.

Praveen
  • 55,303
  • 33
  • 133
  • 164
Jai
  • 74,255
  • 12
  • 74
  • 103
  • Your quotes are messed up...you either have to escape the inner quotes with a backslash, or use single-quotes instead of double-quotes. – nbrooks Apr 17 '14 at 05:08
  • @nbrooks oh yes! Actually typing on smaller screens are little difficult, it was really a typo error. For edits thanks to praveen. – Jai Apr 17 '14 at 05:15
  • Thanks Jai and praveen for your answers – Paresh3489227 Apr 17 '14 at 05:48
1

You can do like this

1) create an empty array.
2) iterate over all lis.
3) push each id to the array as shown below.
4) Then join the array with comma and use it

var ids = [];
$("#tree ul").find("li").each(function () {
    ids.push("#" + this.id);
});

var idsString = ids.join();
//$(idsString)
Praveen
  • 55,303
  • 33
  • 133
  • 164
1

Use something like var obj = $("[id^=dynatree-id]") to get all id's that start with dynatree-id. See: Wildcards in jQuery selectors

Community
  • 1
  • 1
Mattias Åslund
  • 3,877
  • 2
  • 18
  • 17
0

One more solution to this could be -

While assigning the dynamic id's, you can give them a common class, Say class="dynamicLi" and then you wont need to loop through any data item list.

You can simply then use :

$(".dynamicLi")
Janak
  • 4,986
  • 4
  • 27
  • 45