kickout.js和jQueryUI创建一个手风琴菜单 [英] knockout.js and jQueryUI to create an accordion menu

查看:112
本文介绍了kickout.js和jQueryUI创建一个手风琴菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用jquery UI和敲除js进行协作时遇到了一个小问题.基本上,我想创建一个手风琴,并通过foreach(或模板)从敲除中添加项目.

Got a slight problem trying to have jquery UI and knockout js to cohoperate. Basically I want to create an accordion with items being added from knockout through a foreach (or template).

基本代码如下:

<div id="accordion">
    <div data-bind="foreach: items">
        <h3><a href="#" data-bind="text: text"></a></h3>
        <div><a class="linkField" href="#" data-bind="text: link"></a></div>
    </div>
</div>

这里没有什么令人印象深刻的...问题是,如果我做类似的事情:

Nothing impressive here... The problem is that if I do something like:

$('#accordion').accordion();

将创建手风琴,但内部div将是页眉选择器(默认为第一个孩子),因此效果不是想要的.

The accordion will be created but the inner div will be the header selector (first child, as default) so the effect is not the wanted one.

与此相关的问题:

$('#accordion').accordion({ header: 'h3' });

似乎工作得更好,但实际上创建了2个手风琴,而不是一个有2个部分的手风琴...很奇怪.

Seems to work better but actually creates 2 accordions and not one with 2 sections... weird.

我试图探索敲除模板,并使用"afterRender"重新手风琴div,但无济于事...似乎只将第一个链接重新呈现为手风琴,而没有将第二个链接重新呈现为手风琴.无论如何,这可能是由于我对jquery UI的初学者了解.

I have tried to explore knockout templates and using "afterRender" to re-accordionise the div but to no avail... it seems to re-render only the first link as an accordion and not the second. Probably this is due to my beginner knowldge of jquery UI anyway.

您是否知道如何使所有内容协同工作?

Do you have any idea how to make everything work together?

推荐答案

我会使用此类功能的自定义绑定.

I would go with custom bindings for such functionality.

就像 RP Niemeyer 一样,其中包含将jQuery手风琴绑定到剔除js的示例

Just like RP Niemeyer with an example of jQuery Accordion binding to knockoutjs http://jsfiddle.net/rniemeyer/MfegM/

这篇关于kickout.js和jQueryUI创建一个手风琴菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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