本文介绍了jQuery UI Sortable的淘汰赛自定义绑定-奇怪的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery Sortable和Knockout来维护数组.

I'm using jQuery Sortable and Knockout to maintain an array.

http://jsfiddle.net/daniel_white/KrGY8/3/

请注意,当您拖动这些项目时,它们会重复出现或消失.

Notice when you drag the items, they duplicate or disappear.

有人知道我该如何解决吗?

Anyone know how I could fix this?

推荐答案

当您使用jQuery UI sortable进行移动时,基于空文本节点,KO的项目映射会变得有些混乱.

KO's mapping of items gets a little messed up based on empty text nodes when you are moving things around using jQuery UI sortable.

您可以消除模板"中的文本节点,例如: http://jsfiddle.net/rniemeyer/KrGY8/5/

You can either eliminate the text nodes in your "template" like: http://jsfiddle.net/rniemeyer/KrGY8/5/

或者删除现有项目,然后分两步将其放回正确的位置(两次更新observableArray): http://jsfiddle.net/rniemeyer/KrGY8/4/

Or remove the existing item and put it back to the right spot in two steps (updating the observableArray twice): http://jsfiddle.net/rniemeyer/KrGY8/4/

我还写了一个绑定插件,用于在Knockout中与jQuery sortable一起使用,该插件在此处提供了一些其他功能: https://github.com /rniemeyer/knockout-sortable

I also wrote a binding plugin to work with jQuery sortable in Knockout that provides some additional features here: https://github.com/rniemeyer/knockout-sortable

这篇关于jQuery UI Sortable的淘汰赛自定义绑定-奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 12:11