I have the below Dojo DnD and I can't figure out how to delete and add item(s) from/to the catalog source. What I ultimately want to do is allow the users to is:

  1. Drag items from the catalog to the wishlist... this is working fine.
  2. Delete any remaining items in the catalog that were not moved to the wishlist by clicking the Clear List button... need help here.
  3. Be able to add new items to the catalog by clicking another button that is not listed in the below code... need help here.

To summarize, I need to know how to delete items and add items from/to the catalog, and have any moved items remain in the wishlist.

dojo.addOnLoad(function() {
    require([ "dojo/dom-class", "dojo/dnd/Source", "dijit/form/Button", "dojo/domReady!" ], function(domClass, Source){
        var catalog = new Source("catalogNode");
        catalog.insertNodes(false, [
            { data: "Bushmaster <div id='5' style='display:none;'>5</div>"},
            { data: "Colt <div id='4' style='display:none;'>4</div>"},
            { data: "DPMS <div id='6' style='display:none;'>6</div>"},
            { data: "Glock <div id='2' style='display:none;'>2</div>"},
            { data: "Kahr Arms <div id='7' style='display:none;'>7</div>"},
            { data: "Marlin <div id='3' style='display:none;'>3</div>"},
            { data: "Remington <div id='78' style='display:none;'>78</div>"},
            { data: "Rock River Arms <div id='1' style='display:none;'>1</div>"},
            { data: "Smith & Wesson <div id='105' style='display:none;'>105</div>"}
        ]);
        catalog.forInItems(function(item, id, map){
            domClass.add(id, item.type[0]);
        });

        var wishlist = new Source("wishlistNode");

        new dijit.form.Button({
            label: "Clear List",
            onClick: function() {
                alert("Clearing Items");
            }
        },
        "clearListBtn");
    });
});
有帮助吗?

解决方案

Delete all (remaining) elements in a source:

// e.g., var catalog = new Source("catalogNode");
catalog.selectAll().deleteSelectedNodes();

New items can be added at any time by using the very same insertNodes():

catalog.insertNodes(false, additionalData);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top