Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui Ember.js+;jQuery UI可拖动克隆_Jquery Ui_Ember.js - Fatal编程技术网

Jquery ui Ember.js+;jQuery UI可拖动克隆

Jquery ui Ember.js+;jQuery UI可拖动克隆,jquery-ui,ember.js,Jquery Ui,Ember.js,我试图将Ember.js与jQuery UI的可拖动功能结合使用,但遇到了一些问题。具体地说,当使用helper时,我无法删除元素,并且所有内容都非常滞后。如果我不使用克隆助手,一切都会正常工作 我怀疑这与jqueryui克隆html有关,包括所有的变形脚本标记(用于绑定) 我不需要在拖动元素时实时更新它。有没有办法用余烬去掉绑定标签 以下是视图逻辑,仅供参考: didInsertElement: -> @_super() @$().draggable cursor: 'h

我试图将Ember.js与jQuery UI的可拖动功能结合使用,但遇到了一些问题。具体地说,当使用helper时,我无法删除元素,并且所有内容都非常滞后。如果我不使用克隆助手,一切都会正常工作

我怀疑这与jqueryui克隆html有关,包括所有的变形脚本标记(用于绑定)

我不需要在拖动元素时实时更新它。有没有办法用余烬去掉绑定标签

以下是视图逻辑,仅供参考:

didInsertElement: ->
  @_super()
  @$().draggable
    cursor: 'hand'
    helper: 'clone'
    opacity: 0.75
    scope: @draggableScope
  @$().droppable
    activeClass: 'dropActive'
    hoverClass: 'dropHover'
    drop: @createMatch
    scope: @droppableScope
我的第一个想法是尝试在拖动过程中使用
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

任何帮助都将不胜感激。

我通过手动剥离所有与余烬相关的元数据来实现这一点。下面是我制作的一个小jquery插件:

# Small extension to create a clone of the element without
# metamorph binding tags and ember metadata

$.fn.extend
  safeClone: ->
    clone = $(@).clone()

    # remove content bindings
    clone.find('script[id^=metamorph]').remove()

    # remove attr bindings
    clone.find('*').each ->
      $this = $(@)
      $.each $this[0].attributes, (index, attr) ->
        return if attr.name.indexOf('data-bindattr') == -1
        $this.removeAttr(attr.name)

    # remove ember IDs
    clone.find('[id^=ember]').removeAttr('id')
    clone
要使其工作,只需按如下方式设置辅助对象:

helper: ->
  $this.safeClone()

我在使用Ember 1.0.0 RC6时遇到了同样的问题。我发现用返回克隆的函数替换克隆字符串就可以了

  this.$().draggable({
    // helper: 'clone'
    helper: function() {
      return $(this).clone();
    }
  });
咖啡脚本

@$().draggable
    # helper: 'clone'
    helper: ->
        $(@).clone()

那么,之后如何重新启用绑定呢?或者您不在乎吗?绑定仅在用于拖动辅助对象的克隆元素中被禁用。原来的元素仍然完好无损。我想不出有什么东西可以做你想做的事。对我来说,你所拥有的看起来是一个干净的解决方案。如果以后它提供了另一种方法,我可能会研究变质,但现在这是我可以使用的。谢谢“助手”也可以是一个函数。。。因此,您可以构建自己的helper元素,而不是从jQueryUI为您制作的克隆中剥离所有内容。这对我很有效