0

我在 framer.js 中创建了一个包含可拖动列表项的列表,该列表项是用 coffeescript 编写的。

数组“Layers”包含单个列表项。

for i in [0..3]
    layer = new Layer width:listWidth, height:listHeight, y:i*yDistance, clip:false,
    borderRadius: 4, superLayer:canvas

    layer.listIndex = i

    layer.draggable.enabled = true
    layer.draggable.speedX = 0
    layer.draggable.speedY = 1

    Layers.push(layer)

当我现在在列表项上调用事件侦听器时,“层”参数未定义

layer.on Events.DragMove, (event, draggable, layer) ->
    print layer

我需要事件函数中的图层元素来操作它。错误在哪里?

4

1 回答 1

0

删除draggable声明:

layer.on Events.DragMove, (event, layer) ->
    print layer

或者,使用this关键字:

layer.on Events.DragMove, (event, layer) ->
    print this

使用您的代码:

for i in [0..3]
    layer = new Layer width:listWidth, height:listHeight, y:i*yDistance, clip:false,
    borderRadius: 4, superLayer:canvas

    layer.listIndex = i

    layer.draggable.enabled = true
    layer.draggable.speedX = 0
    layer.draggable.speedY = 1

    Layers.push(layer)

    layer.on Events.DragMove, (event, layer) ->
        print layer
        print this
于 2016-11-15T14:11:30.140 回答