Javascript 在typeahead wait ms和发出的请求数之间取得平衡(角度ui typeahead)

Javascript 在typeahead wait ms和发出的请求数之间取得平衡(角度ui typeahead),javascript,angularjs,twitter-bootstrap,angular-ui,typeahead,Javascript,Angularjs,Twitter Bootstrap,Angular Ui,Typeahead,我正在用打字机,我有点问题。具体来说,我正在研究这个变量 typeahead-wait-ms $ (Default: 0) - Minimal wait time after last character typed before typeahead kicks-in. 我发现,通过使用这个变量,并将其设置为300毫秒左右,我大幅减少了对后端的请求数量。这是一件好事 但是,我现在需要等待返回的数据结构,然后才能更新文本栏中的文本 有点像这样 左侧带有“X”的术语是默认高亮显示的术语 1) [f

我正在用打字机,我有点问题。具体来说,我正在研究这个变量

typeahead-wait-ms $ (Default: 0) - Minimal wait time after last character typed before typeahead kicks-in.
我发现,通过使用这个变量,并将其设置为300毫秒左右,我大幅减少了对后端的请求数量。这是一件好事

但是,我现在需要等待返回的数据结构,然后才能更新文本栏中的文本

有点像这样

左侧带有“X”的术语是默认高亮显示的术语

1)
[foo]              <----- current text in text bar
    -X[foo]        <----- original text {"text" : "foo"}
    - [match 1]     <----- match 1 {"text" : "match1"}
    - [match 2]     <----- match 2 {"text" : "match2"}

2)
[foo bar]          <----- updated text in text bar
    -X[foo]        <----- note that the typeahead contents have not yet updated
    - [match 1]     <----- at this point we are fetching matches for "foo bar" from the backend
    - [match 2]    

3)
[foo bar]              <----- updated text in text bar
    -X[foo bar]        <----- after the 300ms, the typeahead contents updates
    - [match 3]    
    - [match 4]    
这是文本栏中的术语,我知道

function select($item, $model, $label) {
    //$item.text = "foo" 
这是内容更新前的最后一个“突出显示的术语”

我试着比较ng模型变量。。。像这样的

// typeahead html
ng-model= "term"
typeahead-on-select="select"

// bound function
function select($item, $model, $label) {
    alert($scope.term);
}
然后$scope.term出现未定义

现在,当我完全删除typeahead wait min时,请求发出的速度比我按enter键的速度要快。所以没关系。。。但我不想对用户输入的每个字符都发出请求

只是随地吐痰。。。是否有一种方法可以立即将原始搜索词放入结果中,然后在准备好结果时填充其余的结果

// typeahead html
ng-model= "term"
typeahead-on-select="select"

// bound function
function select($item, $model, $label) {
    alert($scope.term);
}