Knockout.js嵌套可排序绑定 [英] Knockout.js nested sortable bindings

查看:125
本文介绍了Knockout.js嵌套可排序绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基因敲除插件ockout.js;但是,我遇到了一个我迄今为止无法解决的问题.我有两个可排序的绑定,一个用于存储桶,另一个用于bucketItems.我能够在存储桶之间重新排序bucketItems;但是,我无法重新订购存储桶.您知道为什么会这样吗?我也使用嵌套绑定,但是据我所知,这并不是造成问题的原因.

非常感谢您提供的任何见解.

解决方案

我不知道您的确切结构,但是您可以使用connectClass选项来控制连接哪些可排序列表.例如,如果您这样做:

<ul data-bind="sortable: { data: buckets, connectClass: 'buckets' }">
    <li>
        <span data-bind="text: name"></span>
        <ul data-bind="sortable: { data: items, connectClass: 'items' }">
            <li data-bind="text: name"></li>
        </ul>
    </li>
</ul>

您将只能在存储桶中放置存储桶,在项目中放置一个项目.插件会自动将类添加到父元素.

以下是示例: http://jsfiddle.net/rniemeyer/YaLgL/

如果您不希望在存储桶之间对项目进行排序,则可以将唯一的connectClass应用于每个类似项:

http://jsfiddle.net/rniemeyer/czNe8/

I am working with the knockout.js sortable plugin; however, I ran into a problem that I have so far been unable to solve. I have two sortable bindings, one for buckets and another for bucketItems. I am able to reorder bucketItems between buckets; however, I am unable to reorder buckets. Would you have any idea why this would be? I am also using nested with bindings, but as far as I can tell, this is not what is causing problems.

I would greatly appreciate any insight you have to offer.

解决方案

I don't know your exact structure, but you can use the connectClass option to control which sortable lists are connected. For example, if you did this:

<ul data-bind="sortable: { data: buckets, connectClass: 'buckets' }">
    <li>
        <span data-bind="text: name"></span>
        <ul data-bind="sortable: { data: items, connectClass: 'items' }">
            <li data-bind="text: name"></li>
        </ul>
    </li>
</ul>

You would only be able to drop a bucket within buckets and an item within items. The plugin automatically adds the class to the parent element.

Here is a sample: http://jsfiddle.net/rniemeyer/YaLgL/

If you did not want to be able to sort items between buckets, then you could apply a unique connectClass to each like:

http://jsfiddle.net/rniemeyer/czNe8/

这篇关于Knockout.js嵌套可排序绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆