我正在使用angular bootstrap typeahead
。我想爲infinite scroll
添加一個功能,因爲我爲滾動功能添加了一個小指令,並且在typeahead
模板中進行了一些更改,滾動指令的工作方式與預期的相同,但在更新結果後鍵入不更新視圖。添加新數據以滾動顯示結果
我的輸入是這樣的:
<input type="text" ng-model="variable" placeholder="Search..." typeahead="obj as obj.text for obj in getObject($viewValue)" typeahead-wait-ms="500" />
預輸入模板:
<ul class="dropdown-menu typeahead-custom" ng-scroll="getObject('{{query}}')" ng-scroll-direction="down" ng-show="isOpen()" ng-style="{top: position.top+'px', left: position.left+'px'}" style="display: block;" role="listbox" aria-hidden="{{!isOpen()}}">
<li ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)" role="option" id="{{match.id}}" should-focus="isActive($index)">
<div typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
</li>
</ul>
和的getObject功能:
$rootScope.lastResult = [];
$rootScope.getObject = function(str) {
return $http({
url: "someUrl",
method: "post",
headers: {'Content-Type': 'application/json'},
data: {str: str, page_limit: 10}
}).then(function(response) {
$.merge($rootScope.lastResult, response.data.data);
return $rootScope.lastResult;
});
};
當我輸入鍵盤緩衝輸入的東西它的工作原理精細,但是當我滾動到typeahead模板時,它會調用一個函數並更新lastResult
變量,但未更新類型的DOM元素。
任何幫助?請....
你在結果更新後嘗試過'$ scope.apply()'嗎? – Anita
[訪問此鏈接https://github.com/angular-ui/bootstrap/blob/master/src/typeahead/typeahead.js 您可能想編輯該文件 – samir