【问题标题】:is there anyway to get fcbkcomplete working in a jquery ui dialog无论如何让 fcbkcomplete 在 jquery ui 对话框中工作
【发布时间】:2011-03-05 06:21:16
【问题描述】:

我看到其他关于此的问题说解决方案是设置 autoOpen = true 但我不想让 autoopen 为 true。

有没有办法让 fcbkcomplete 在没有 autoOpen = true 的情况下在 jquery 对话框上工作。

【问题讨论】:

    标签: jquery jquery-ui-dialog fcbkcomplete


    【解决方案1】:

    鉴于您的反馈,这里是更新。

    $( ".selector" ).dialog({
        open: function(event, ui)
        {
            $("element").fcbkcomplete({
                json_url: "fetched.txt",
                cache: true,
                filter_case: true,
                filter_hide: true,
                newel: true
            });
        }
    });
    

    希望对您有所帮助。

    【讨论】:

    • 我了解如何使用 jquery UI 对话框。我的问题是基于 fcbkcomplete 似乎在 jquery ui 对话框中不起作用的事实。你的回答没有回答那个问题
    • 我更新了上面的代码,让它在 UI modal 打开时触发 fbckcomplete。
    【解决方案2】:

    ooo 什么似乎不起作用?你能解释一下你想要做的更多吗?只是我已经设置了基本的 FCBKcomplete 演示,将它放在一个对话框中并触发它,它会建议一些事情 - 你能举一个不适合你的例子吗?

    这是我使用的代码:

    HTML:

    <div id="myDialog"> 
        <h1>FCBKcomplete Demo</h1> 
        <form action="submit.php" method="POST" accept-charset="utf-8"> 
            <select id="select3" name="select3"> 
                <option value="test1">sleep</option> 
                <option value="test3">sport</option> 
                <option value="test3">freestyle</option> 
                <option value="2">Терешкова Валентина</option> 
            </select> 
            <br/> 
            <br/> 
            <input type="submit" value="Send"> 
        </form> 
    </div>
    <input type="button" id="trigger" value="Open Dialog" />
    

    还有 javascript:

    $("#myDialog").dialog({ 
        autoOpen: false,
        width: 550, 
        modal: true, 
        title: "FCBKcomplete Trial" 
    });
    $("#select3").fcbkcomplete({
        json_url: "/echo/json/",
        addontab: true,
        cache: true,
        height: 2                    
    });
    $("#trigger").click(function() {
       $("#myDialog").dialog('open'); 
    }).button();
    

    它的demo是here


    请多多包涵,该示例占用了大量代码。现在有三个示例,两个有效,一个无效。

    简要说明,jQuery 代码通常在页面加载完成后运行。当所有项目都在那里时,它完成加载。因此,当您使用 ajax 添加项目时,您最初所做的任何事情都不会影响新项目。所以现在你需要重新做一些事情来影响新的项目。

    注意:由于我无法使用 ajax 加载 HTML,所以我通过点击模拟了它...

    // EXAMPLE ONE: (working)
        $("#dialogOne").dialog({ 
            autoOpen: false,
            width: 550, 
            modal: true, 
            title: "FCBKcomplete Trial" 
        });
        $("#selectOne").fcbkcomplete({
            json_url: "/echo/json/",
            addontab: true,
            cache: true,
            height: 2                   
        });
        $("#triggerOne").click(function() {
           $("#dialogOne").dialog('open'); 
        }).button();
    // ABOVE SHOULD WORK CORRECTLY: its static DOM items, 
    // there is a little clue for later......
    
    
    
    // EXAMPLE TWO: (broken)
        // Replicate loading data - as though it had been returned from ajax:
        $("#loadTwo").click(function() {
            // Add the data to the end of the page:
            $("body").append(''
               +'<div id="dialogTwo"> '
               +'     <h1>FCBKcomplete Demo Two</h1> '
               +'     <form action="submit.php" method="POST" accept-charset="utf-8"> '
               +'         <select id="selectTwo" name="selectTwo"> '
               +'             <option value="test1">sleep</option> '
               +'             <option value="test3">sport</option> '
               +'             <option value="test3">freestyle</option> '
               +'             <option value="2">Терешкова Валентина</option> '
               +'         </select> '
               +'         <br/> '
               +'         <br/> '
               +'         <input type="submit" value="Send"> '
               +'     </form> '
               +' </div>'
               +' <input type="button" id="triggerTwo" value="Open Dialog Two" /><br/><br/');
        }).button();
    
        // Just as before setup the dialog (buuuut, the div isn't there yet ;) ):
        $("#dialogTwo").dialog({ 
            autoOpen: false,
            width: 550, 
            modal: true, 
            title: "FCBKcomplete Trial" 
        });
        // Initiate the FCBKcomplete (buuuut, the select input isn't there yet ;) ):
        $("#selectTwo").fcbkcomplete({
            json_url: "/echo/json/",
            addontab: true,
            cache: true,
            height: 2                    
        });
        // Add a listener to show the dialog containing the FCBKcomplete...:
        $("#triggerTwo").click(function() {
           $("#dialogTwo").dialog('open'); 
        }).button();
    // ABOVE SHOULD FAIL: It will load the 'dynamic' items (imagine 
    // $("body").append(....); being the success callback of an ajax
    // function loading data) but remember, the other code runs when 
    // the page is ready, buuut the items aren't actually there yet!
    
    // EXAMPLE THREE: (working)
        // Replicate loading data - as though it had been returned from ajax:
        $("#loadThree").click(function() {
            // Add the data to the end of the page:
            $("body").append(''
               +'<div id="dialogThree"> '
               +'     <h1>FCBKcomplete Demo Three</h1> '
               +'     <form action="submit.php" method="POST" accept-charset="utf-8"> '
               +'         <select id="selectThree" name="selectThree"> '
               +'             <option value="test1">sleep</option> '
               +'             <option value="test3">sport</option> '
               +'             <option value="test3">freestyle</option> '
               +'             <option value="2">Терешкова Валентина</option> '
               +'         </select> '
               +'         <br/> '
               +'         <br/> '
               +'         <input type="submit" value="Send"> '
               +'     </form> '
               +' </div>'
               +' <input type="button" id="triggerThree" value="Open Dialog Three" /><br/><br/');
            // This time setup the dialog INSIDE the 'success' callback:
            $("#dialogThree").dialog({ 
                autoOpen: false,
                width: 550, 
                modal: true, 
                title: "FCBKcomplete Trial Three" 
            });
            // Initiate the FCBKcomplete again INSIDE the 'success' callback:
            $("#selectThree").fcbkcomplete({
                json_url: "/echo/json/",
                addontab: true,
                cache: true,
                height: 2                    
            });
            // Add a listener to show the dialog containing the FCBKcomplete:
            $("#triggerThree").click(function() {
               $("#dialogThree").dialog('open'); 
            }).button();            
        }).button();
    // ABOVE SHOULD WORK: Now the data is being loaded dynamically, 
    // just as example two. However this time we initiate the dialog
    // and FCBKcomplete from the 'success' callback. That way, the 
    // dynamic HTML has already been loaded, so when you try to intiate
    // them they will work!
    

    更新的演示是here

    【讨论】:

    • 我认为问题在于我正在从服务器动态加载我的对话框的 div,所以我认为这是您的示例(确实有效)与我的示例不工作之间的区别。问题可能更多的是关于你可以让 fcbkcomplete 使用来自 ajax 响应的动态 html 吗??
    • 好的,根据我对您的问题的理解,我已添加到示例中。我已经发布了上面的 NEW 代码,以及查看它工作的新链接。我已经尽力解释了。不过,一个主要问题是,您只是加载建议,还是ALL HTML?该示例加载所有 HTML,包括 DIV。只是添加&lt;option&gt;'s 会让事情变得更难......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-17
    • 2017-04-25
    • 1970-01-01
    相关资源
    最近更新 更多