简体   繁体   English

Knockout.js和FancyForms:可见绑定在使用transformSelect的选择框上不起作用

[英]Knockoutjs & FancyForms: visible-binding not working on selectboxes using transformSelect

so I discovered the following problem using knockoutjs (v 3.2.0) and fancyforms (v 1.4.2) together in a webapplication: 因此,我在Web应用程序中同时使用基因敲除js(v 3.2.0)和fancyforms(v 1.4.2)发现了以下问题:

I've got two select boxes(referred to as "dropdown" further on) and two links on a html-page. 我在HTML页面上有两个select框(进一步称为“下拉列表”)和两个链接。

Now the desired behaviour is the following (just a short pseudocode, see below for jsfiddle-scenarios): 现在所需的行为如下(只是一个简短的伪代码,请参见下面的jsfiddle-scenarios):

if(dropdown1.value == "a1"){
    dropdown2.value = "b3";
    dropdown2.hide()
    chosenlinkbutton = chosenlinkbutton1;
    chosenlinkbutton2.hide(); //realized via knockoutjs-visiblebinding and a param
} else {
    //show and reset stuff...
}

The Problem is: my second dropdown does not get hidden. 问题是:我的第二个下拉菜单没有隐藏。 Instead, there appears another dropdown. 而是出现了另一个下拉列表。 As I investigated this problem , I found out it is because fancyform transforms the actual selectbox into ul/li-list structure. 在研究此问题时,我发现这是因为fancyform将实际的选择框转换为ul / li-list结构。 But to be honest I have no clue on how to (re-)apply my binding to the generated code of fancyform or to re-instantiate fancyform after changing the value, so I hope you could help me out here. 但是老实说,我不知道如何在更改值后将我的绑定(重新)应用到生成的fancyform代码或重新实例化fancyform,所以希望您能在这里为我提供帮助。

JSFiddle showing the problem. JSFiddle显示了问题。 Just change "weekView" to "monthView" to see that the other dropdown does not disappear: http://jsfiddle.net/fnmav1e8/8/ 只需将“ weekView”更改为“ monthView”,即可看到其他下拉菜单不会消失: http : //jsfiddle.net/fnmav1e8/8/

And a working JSFiddle with commented-out fancyform: http://jsfiddle.net/fnmav1e8/7/ 还有一个工作正常的JSFiddle,带有注释掉的fancyform: http : //jsfiddle.net/fnmav1e8/7/

In this version, I actually just commented out the line 在这个版本中,我实际上只是注释掉了

$("select").transformSelect();

But sadly I need the app to work with fancyform, so I hope some of you could help me out here! 但是可悲的是,我需要该应用程序才能与fancyform一起使用,所以我希望你们中的一些人可以在这里帮助我!

Best regards, Dominik 最好的问候,多米尼克

UI toolkits like Bootstrap and Fancy Forms often rewrite the DOM to introduce stylized versions of the standard widgets. 诸如Bootstrap和Fancy Forms之类的UI工具箱通常会重写DOM以引入标准小部件的风格化版本。 The trick to controlling their visibility in Knockout is to put the Knockout bindings on a container around the widgets. 控制它们在Knockout中的可见性的技巧是将Knockout绑定放在小部件周围的容器上。

    <div data-bind="visible:isWeekView">
        <select id="selectCals" data-bind="value: mode">
            <option value="default">Default</option>
            <option value="defaultplus">Standard plus</option>
            <option value="none">nothing</option>
        </select>
    </div>

Alternatively, you can use an if binding , which has the advantage of working in virtual tags . 或者,您可以使用if绑定 ,它具有在虚拟标记中工作的优势。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM