DOJO实例化和使用源码的区别
我是 DOJO 的新手,试图找出这两个看似两个东西的两种用途之间的区别。
dndController: new dijit.tree.dndSource("dijit.tree.dndSource",{copyOnly:true})
第二个有效,但是
dndController: "dijit.tree.dndSource"
当我使用第一个时,它在加载树时给我一个错误。它说类型节点未定义。我想使用第一个的原因是因为我想将 copyOnly 设置为 true。
任何答案都表示赞赏。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该参数需要一个构造函数函数,而不是您传递的对象。也许以下内容会起作用:
一些解释:
我实际上对树上的拖放一无所知。我所做的就是查看 Tree 源代码(位于 dijit/Tree.js 或类似的代码)以找出使用 dndController 的位置。从那时起,我可以发现它应该是一个可以接收这两个参数的函数(或表示此类函数的路径的字符串......)。我刚刚从您的问题陈述中复制了实际使用的 dijit.tree.dndSource 函数,希望它能起作用。
dojo.mixin 函数将其第二个、第三个……参数中的所有对象混合到第一个参数中。通过使用新的空对象作为“接收”对象,我们有一种巧妙的方法来制作 params 的浅表副本,设置 copyOnly 而不修改原始 params 对象。
That parameter expects a constructor function instead of the object you passed. Perhaps the following would work:
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.