2014-02-13 54 views
0
YUI().use('dd-constrain', 'dd-proxy', 'dd-drop', function(Y) { 
var lis = Y.Node.all('#listContainer ul li');//Get a NodeList of all li 
lis.each(function(v,k) { 
    var dd = new Y.DD.Drag({ 
     node:v, 
     //Make it Drop target and pass this config to the Drop constructor 
     //Not sure what this actually means 
     target: { 
      padding: '0 0 0 20' 
     } 
    }).plug(Y.Plugin.DDProxy, { 
     //Don't move the node at the end of the drag 
     moveOnEnd:false 
    }).plug(Y.Plugin.DDConstrained, { 
     //Keep it inside the #listContainer node 
     constrain2node: '#listContainer' 
    }); 
}); 

参数v和k在函数中指的是什么?看起来v是节点,这可能是有道理的,但那么k是什么?此外,“目标:”部分是做什么的?这个YUI函数中的参数v和k是指什么?

+0

'value'的内容/值和'key',共同对数组/对象 – helion3

+0

是迭代的时候,但我想知道什么是价值,关键是在YUI节点中 – michaelAdam

+1

您正在迭代'lis.each',它是'#listContainer'中的列表项元素。所以'value'就是'li','key'可能是一个数字索引,'0,1,2'等。 – helion3

回答

0

According to the docs,你会被通过:

  • 当前节点实例
  • 节点索引(在列表中的位置)
  • 你的回调只是定义两个节点列表本身

参数,这很好

0

循环中项目的当前值,你得到了所有的<li>之前,所以可能会是每个<li>

相关问题