实例化和使用源之间的DOJO差异 [英] DOJO difference between instantiation and using source
问题描述
dndController:new dijit.tree.dndSource(dijit.tree.dndSource,{copyOnly:true})
和
dndController:dijit.tree.dndSource
第二个工作,但是当我使用第一个一,加载我的树给我一个错误。它表示类型节点未定义。我想使用第一个的原因是因为我想将copyOnly设置为true。
任何答案都赞赏它。
该参数期望一个构造函数函数,而不是您传递的对象。也许以下的工作:
dndController:function(arg,params){
return new dijit.tree.dndSource (
arg,//不要弄乱第一个参数
dojo.mixin({},params,{copyOnly:true}))
//创建参数的副本对象,但将copyOnly设置为true
}
某些说明:
我实际上不知道有关拖放在树上的任何内容。我所做的只是查看Tree源代码(它的dijit / Tree.js或类似的东西),以找出使用dndController的位置。从那时起,我可以发现,这应该是一个可以接收这两个参数的函数(或一个表示这样的函数的路径的字符串)。使用的实际dijit.tree.dndSource函数只是从你的问题语句中复制出来,希望它可以正常工作。
dojo.mixin函数将所有对象中的其第二,第三,...参数进入第一个参数。通过使用一个新的,空的对象作为接收对象,我们有一个简单的方法来制作一个浅色的params副本,在不修改原始params对象的情况下设置copyOnly。
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.
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.
这篇关于实例化和使用源之间的DOJO差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!