Javascript 如何将dnd特性应用于dojo中html中动态创建的div
我想使用dojo将dnd应用于动态创建的div。我已经尝试了很多方法来应用dnd特性。这是我的密码Javascript 如何将dnd特性应用于dojo中html中动态创建的div,javascript,dojo,Javascript,Dojo,我想使用dojo将dnd应用于动态创建的div。我已经尝试了很多方法来应用dnd特性。这是我的密码 var inputdiv = document.createElement('div'); inputdiv.setAttribute("id", count); inputdiv.style.background = "white"; inputdiv.style.height = "30px"; inputdiv.style.width = "60px"; dojo.addClass(inpu
var inputdiv = document.createElement('div');
inputdiv.setAttribute("id", count);
inputdiv.style.background = "white";
inputdiv.style.height = "30px";
inputdiv.style.width = "60px";
dojo.addClass(inputdiv, "dojoDndItem");
calculation.appendChild(inputdiv);
如果手动将带有
dojoDndItem
类的DOM节点添加到dnd源的DOM节点,则可以调用dnd源(实际实例,而不是其DOM节点)上的sync
,使其根据DOM中现在的内容更新其数据
中列出了sync
方法
另外,FWIW,您可以使用dojo.create
(您似乎正在从遗留全局访问dojo API,因此在本例中我也将这样做):
如果我想将动态创建的div作为目标,我如何调用sync()。如果所说的目标是指
dojo/dnd/Target
的一个实例,那么这只是dojo/dnd/Source
的一个扩展,因此同样的原则也适用于此。无论哪种方式,您都需要对实际的dojo/dnd
实例的引用。
dojo.create('div', {
className: 'dojoDndItem',
id: count,
// Note: it would be more ideal to apply styles via CSS rather than inline
style: {
background: 'white',
height: '30px',
width: '60px'
}
}, calculation);
// Then call sync() on the dnd source once you've finished adding nodes