2016-08-17 9 views
0

私はHorsey pluginを使用して、テキスト入力用のオートコンプリートを作成しています。私はキーと値のペア(3番目の例here)を使用しています。私は検索のテキスト値ではなく、キー値(私のアプリのID)をPOSTしたいと思います。オートコンプリートテキストの値を取得する方法[Horseyプラグインを使用]

horsey(document.querySelector('#search_field'), { 
    source: [{ list: [ 
    { value: 'banana', text: 'Bananas from Amazon Rainforest' }, 
    { value: 'apple', text: 'Red apples from New Zealand' }, 
    { value: 'orange', text: 'Oranges from Moscow' }, 
    { value: 'lemon', text: 'Juicy lemons from the rich Amalfitan Coast' } 
    ]}], 
    getText: 'text', 
    getValue: 'value' 
}); 

私はどこからでもgetValue関数を呼び出さなければならないことを理解していますが、わかりません。

+0

フィールドに値を入力したら、そのフィールドに値を設定しますか? –

+0

フィールドにはテキストが入力されていますが、キー(値)を取得する方法はありません:( – Honesta

+0

要素に属性またはHTMLとして存在しますか? –

答えて

1

タグを挿入すると実行されるpredictNextSearch(info)を使用できます。

horsey(document.querySelector('#search_field'), { 
    source: [{ list: [ 
    { value: 'banana', text: 'Bananas from Amazon Rainforest' }, 
    { value: 'apple', text: 'Red apples from New Zealand' }, 
    { value: 'orange', text: 'Oranges from Moscow' }, 
    { value: 'lemon', text: 'Juicy lemons from the rich Amalfitan Coast' } 
    ]}], 
    getText: 'text', 
    getValue: 'value', 
    predictNextSearch(info) { 
     //get the suggestion selected by the user 
     console.log(info.selection.value); 
    } 
}); 

+0

ありがとう、今、私は入力フィールドの値属性をpredicNextSearchを使って設定できます良い解決策のように。再度、感謝します! – Honesta

関連する問題