3

when using insertNodes a unique id will be created for the nodes.

insertNodes(addSelected, data, before, anchor)

How do we assign a certain name / text as an id for the new nodes?

hugomg
  • 68,213
  • 24
  • 160
  • 246
wong chung yie
  • 175
  • 1
  • 4
  • 14
  • possible duplicate of [set attribute while using insertnodes in dojo](http://stackoverflow.com/questions/8514772/set-attribute-while-using-insertnodes-in-dojo) – hugomg Dec 15 '11 at 11:20

1 Answers1

3

Create a custom "creator" function, and set the id on the item. Example :

In your html

<ol id="listNode">
</ol>

In your javascript :

require(["dojo/dnd/Source"]);

function myCreator( item, hint ) {
    var myLi = dojo.create( 'li', { id : item.id, innerHTML: item.text });

   if (hint == 'avatar') {
      // create your avatar if you want
      myLi.innerHTML = "Moving " + item.text + "...";
   }
   return {node: myLi, data: item, type: "foo"};
}

dojo.ready(function() {
    var list = new dojo.dnd.Source("listNode", {creator: myCreator});

    list.insertNodes(false, [
        { id : "id1", text : "foo"},
        { id : "id2", text : "bar"},
        { id : "id3", text : "baz"}
    ]);
});
Philippe
  • 6,703
  • 3
  • 30
  • 50