hbhakhra
hbhakhra

Reputation: 4236

DOJO difference between instantiation and using source

I am new to DOJO and trying to figure out the difference between these two uses of the seemingly two things.

dndController: new dijit.tree.dndSource("dijit.tree.dndSource",{copyOnly:true})

and

dndController: "dijit.tree.dndSource"

The second one works, but when I use the first one, it gives me an error when loading my tree. It says type node is undefined. The reason I want to use the first one though is because I want to set copyOnly to true.

Any answers appreciated it.

Upvotes: 1

Views: 376

Answers (1)

hugomg
hugomg

Reputation: 69934

That parameter expects a constructor function instead of the object you passed. Perhaps the following would work:

dndController: function(arg, params){
    return new dijit.tree.dndSource(
        arg,  // don't mess up with the first parameter
        dojo.mixin({}, params, {copyOnly:true}))
           //create a copy of the params object, but set copyOnly to true
}

Some explanation:

I actually don't know anything about drag-and-drop on trees. All I did was look at the Tree source code (its at dijit/Tree.js or something like that) to find out where dndController is used. From that point I could find out that is was supposed to be a function that can receive these two parameters (or a string representing the path to such a function...). The actual dijit.tree.dndSource function that is used I just copied from your question statement, hoping it would work.

The dojo.mixin function mixes in all the objects in its 2nd, 3rd, ... arguments into the first argument. By using a new, empty, object as the "receiving" object we have a neat way to make a shallow copy of params, settting copyOnly without modifying the original params object.

Upvotes: 3

Related Questions