在滚动时将新数据添加到预先输出结果

Arj*_*jun 24 angularjs angularjs-directive angular-ui-bootstrap angular-ui-typeahead

我正在使用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" />
Run Code Online (Sandbox Code Playgroud)

预先模板:

<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>
Run Code Online (Sandbox Code Playgroud)

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;
    });
};
Run Code Online (Sandbox Code Playgroud)

当我在typeahead输入中键入内容时,它工作正常,但是当我滚动到typeahead模板时,它调用一个函数并更新lastResult变量,但没有更新typeaheadDOM元素.

有帮助吗?请....

Bra*_*oks 0

我写过类似的东西,但没有使用滚动,而是单击了一个按钮。

UI Bootstrap 不公开其指令的任何 API,因此我需要扩展其模板,并通过指令添加一个额外的控制器,该指令将操纵发送到 type advance 指令的数据。

简而言之,它很脏,我建议尝试寻找除 UI Bootstrap 之外的另一个用于类型提前功能的库。