jqueryui自动完成。我做错了什么

时间:2012-11-08 02:47:16

标签: jquery-ui jquery-autocomplete

所以继承人是从输入和“#key”变量调用两个变量的问题,从“split(this.value);”中调用数据库中的最后一个调用。像这样做出来

//这很好

touser:karen galante,jor monucha,wappa,

//这需要

rnkey:karen galante,jor monucha,gdhdf9j7hd98fg7dfn,

// nappppaa8686f86df8,iuof79f79ds7h8j7kg70gfd70fg8dsf,gdhdf9j7hd98fg7dfn,

我是jquery ui和iv的新手,现在正在为这个代码工作一天,任何想法

$(function() {
    var availableTags = [
    {
            value: "iuof79f79ds7h8j7kg70gfd70fg8dsf",
            label: "jor monucha",
            desc: "the write less, do more, JavaScript library",
            icon: "16.png"
    },
            {
            value: "nappppaa8686f86df8",
            label: "karen galante",
            desc: "the write less, do more, JavaScript library",
            icon: "16.png"
    },        {
            value: "gdhdf9j7hd98fg7dfn",
            label: "wappa who",
            desc: "the write less, do more, JavaScript library",
            icon: "16.png"
    },
        ];
    function split( val ) {
        return val.split( /,\s*/ );
    }
    function extractLast( term ) {
        return split( term ).pop();
    }

    $( "#tags" )
        // don't navigate away from the field on tab when selecting an item
        .bind( "keydown", function( event ) {
            if ( event.keyCode === $.ui.keyCode.TAB &&
                    $( this ).data( "autocomplete" ).menu.active ) {
                event.preventDefault();
            }
        })
        .autocomplete({
            minLength: 2,
            source: function( request, response ) {
                // delegate back to autocomplete, but extract the last term
                response( $.ui.autocomplete.filter(
                    availableTags, extractLast( request.term ) ) );
            },
            focus: function() {
                // prevent value inserted on focus
                return false;

            },







       select: function( event, ui ) {
            $( "#project" ).val( ui.item.label );
            $( "#project-id" ).val( ui.item.value );
            $( "#project-description" ).html( ui.item.desc );
            $( "#project-icon" ).attr( "src", "images/" + ui.item.icon );


                var hintkey = split( this.value );
                // remove the current input
                hintkey.pop();
                // add the selected item
                hintkey.push( ui.item.value );
                // add placeholder to get the comma-and-space at the end
                hintkey.join( ", " );
                hintkey.push( "" );

                $( "#key" ).val(hintkey);

                var terms = split( this.value );
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push( ui.item.label );
                // add placeholder to get the comma-and-space at the end
                terms.push( "" );
                this.value = terms.join( ", " );

0 个答案:

没有答案