Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set id when using insertnodes in dojo

Tags:

dojo

dojo-dnd

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?

like image 213
wong chung yie Avatar asked Jun 30 '26 09:06

wong chung yie


1 Answers

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"}
    ]);
});
like image 131
Philippe Avatar answered Jul 01 '26 23:07

Philippe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!