简体   繁体   English

调用Jquery自动完成ajax函数

[英]Call Jquery Autocomplete ajax function

I have a Jquery autocomplete ajax function whose source is calculated from code behind. 我有一个jQuery自动完成ajax函数,其源代码是从后面的代码计算得出的。 however I am getting the source in javascript using client script manager but my function doesn't execute. 但是我使用客户端脚本管理器在javascript中获取源代码,但我的函数没有执行。

Apart from that I am trying to call that ajax function from code behind through 除此之外,我试图从后面的代码中调用该ajax函数。

ClientScriptManager.RegisterStartupScript()

But again my function doesn't execute. 但是我的功能再次没有执行。 My function is: 我的功能是:

<form id="form1" runat="server">
    <div>
        <input id="Text1" type="text"/>&nbsp;&nbsp;&nbsp;
        <input id="Text2" type="text" /><br />
        <br />
        <input id="Button2" type="button" value="button" />

    <script type="text/javascript">
    var mydataformat = [{ label: "....", value: "....", icon: "....." }, 
                        { label: "....", value: ".....", icon: "....." }];

    $(function() {
    $("#Text1").autocomplete({                      
    minLength: 0,                      
    source: JSVar,                      
    focus: function (event, ui) 
    {
    $("#Text1").val(ui.item.label);                          
    return false;                      
    }})                     
    .data("autocomplete")._renderItem = function (ul, item) {                         
    return $("<li></li>") 
    .data("item.autocomplete", item)                             
    .append("<a><img src='" + item.icon + "' width='32' height='32' />  " + item.label + "</a>")                             
    .appendTo(ul);                     
        }; 
    });

</script>

You have to set the source when your data has been loaded like mentioned here : 你必须设置源时,你的数据已经加载喜欢提到这里

$("#Text1").autocomplete( "option", "source", ["your", "loaded", "data"] );

...or better initialize your autocomplete when your calculated data is ready, not earlier. ...或者更好地在计算出的数据准备就绪时初始化自动完成,而不是更早。

Take a look at the Custom Data sample on the jQueryUI site, it seems to cover everything you want. 看一下jQueryUI网站上的Custom Data示例 ,它似乎涵盖了你想要的一切。 It uses label, value, icon etc. 它使用标签,价值,图标等。

The only remaining piece is to wait until after your data has loaded before you initialise it. 唯一剩下的部分是等到数据加载完毕后再进行初始化。

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

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