2017-06-28 6 views
0

文全体に対してtextcompleteを使用しようとしています。私は別の正規表現をたくさん試しましたが、 ".textcomplete"はまだ文の最初の単語を検索します。.textcompleteを使用して文全体のテキストを完成

誰か良いですか?

$('#search').textcomplete([{ 
    words: array, 
    match: /\b(\w{1,})$/, 
    search: function (term, callback) { 
     term = term.toLowerCase(); 
     callback($.map(array, function (word) { 
      return word.toLowerCase().indexOf(term) === 0 ? word : null; 
     })); 
    }, 
    select: function (value, strategy) { 
     this.adapter.select(value, strategy); 
     this.fire('change').fire('textComplete:select', value, strategy); 
     this.adapter.focus(); 
    }, 
    index: 1, 
    replace: function (word) { 
     return word; 
    }, 

}], { 
    onKeydown: function (e, commands) { 
     if (e.ctrlKey && e.keyCode === 74) { // CTRL-Enter 
      return commands.KEY_ENTER; 
     } 
    } 

}); 

Working with the first word

Autocomplete stops when pressing space

答えて

0

このため、あなたの正規表現は、ホワイトスペースと一致していません!

match: /\b(\w{1,})$/ 

wは、スペースではなく任意の単語に一致する略語です。それを試してみてください

match: /\b([a-zA-Z0-9_ ]{1,})$/ 

http://jsfiddle.net/p5qqvkp6/12/

任意の単語、代わりにスペースに一致するように正規表現を使用します
関連する問題