0

jQuery UI オートコンプリートで文字列の最初の数文字のみを検索しようとしています。jQuery UI でキー/値のことをできると思っていましたが、それが当てはまるかどうかはわかりません。

次の文字列があります。

AGREE Agreement by and between BLANK, in BLANK, of the county records. 

文字列の残りの部分ではなく、のみAGREEを検索する必要があります。 AGREEユーザーが検索するテキストコードです。

これが私の簡単なコードです:

var availableTags = [
            "AGREE Agreement by and between BLANK, in BLANK, of the county records.",
            "CONDO Covenants, conditions, restrictions, reservations, terms, provisions, easements, liens for assessments, options, powers of attorney and limitations on title as set forth in the Ohio Revised Code Chapter 5311, or as set forth in the Declaration of Condominium ownership and Bylaws as recorded in BLANK, as amended, plat BLANK, of the county records."
        ];

$( "#tags" ).autocomplete({
 source: availableTags
});

残りの文字列ではなく、最初の単語AGREEとのみCONDOを検索する必要があります。これは可能/実行可能ですか?

4

2 に答える 2

1

タグだけを検索しているのなら、タグを配列に入れてみませんか?

于 2013-03-02T20:40:26.197 に答える
1

私の解決策はこれでした:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>autocomplete demo</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
</head>
<body>
<label for="autocomplete">Select a programming language: </label>
<input id="autocomplete">
<script>
var tags = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ];
$( "#autocomplete" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags, function( item ){
return matcher.test( item );
}) );
}
});
</script>
</body>
</html>

参考文献 http://api.jqueryui.com/autocomplete/#event-search (ページの下部)

于 2013-03-02T21:04:39.703 に答える