我很难搞清楚如何移动数组元素.例如,给出以下内容:
var arr = [ 'a', 'b', 'c', 'd', 'e'];
Run Code Online (Sandbox Code Playgroud)
我怎么能写一个'd'以前移动的函数'b'?
还是'a'之后'c'?
移动后,应更新其余元素的索引.这意味着在第一个例子中,移动arr [0]将='a',arr [1] ='d'arr [2] ='b',arr [3] ='c',arr [4] = 'E'
这看起来应该很简单,但我无法绕过它.
我试图将Ember.js与jQuery UI的可拖动功能结合使用,但我遇到了问题.具体来说,当使用克隆助手时,我无法删除元素,一切都非常滞后.如果我不使用克隆助手,一切都按预期工作.
我怀疑这与jQuery UI克隆html有关,包括所有的变形脚本标签(用于绑定).
我拖动它时不需要更新元素.有没有办法剥离绑定标签与ember?
作为参考,这里是视图逻辑:
didInsertElement: ->
@_super()
@$().draggable
cursor: 'hand'
helper: 'clone'
opacity: 0.75
scope: @draggableScope
@$().droppable
activeClass: 'dropActive'
hoverClass: 'dropHover'
drop: @createMatch
scope: @droppableScope
Run Code Online (Sandbox Code Playgroud)
我的第一个想法是尝试使用a beginPropertyChanges并endPropertyChanges在拖动期间防止意外行为.这似乎不起作用,也不是理想的,因为我希望其他绑定更新.以下是我尝试过的修改后的代码:
didInsertElement: ->
@_super()
@$().draggable
cursor: 'hand'
helper: 'clone'
opacity: 0.75
scope: @draggableScope
start: ->
Ember.beginPropertyChanges()
stop: ->
Ember.endPropertyChanges()
@$().droppable
activeClass: 'dropActive'
hoverClass: 'dropHover'
drop: @createMatch
scope: @droppableScope
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.