gpt4 book ai didi

javascript - 关于过滤器输入和重置索引的 ng-change 的 Material 虚拟重复更新列表?

转载 作者:行者123 更新时间:2023-12-03 06:11:39 26 4
gpt4 key购买 nike

我已在此 plnkr 中复制了该场景:

<input type="text" ng-model="search.id" ng-change="ctrl.infiniteItems.fetchMoreItems_()">

var vm = this;
vm.infiniteItems = {
numLoaded_: 0,
toLoad_: 0,
items: [],

// Required.
getItemAtIndex: function(index) {
if (index > this.numLoaded_) {
this.fetchMoreItems_(index);
return null;
}

return this.items[index];
},

// Required.
getLength: function() {
return this.numLoaded_ + 3;
},

fetchMoreItems_: function(index) {
if (this.toLoad_ < index) {
this.toLoad_ += 10;
var filtered = [];
fetcher.fetch($scope.search.id).then(angular.bind(this, function(obj) {
this.items = obj;
this.numLoaded_ = this.toLoad_;
if (obj.length <= this.toLoad_) {
this.items = this.items.concat(obj);
this.numLoaded_ = this.toLoad_;
}
}));
}
}
}

https://plnkr.co/edit/vnrEOmQJ96ZETQpzlaMj

我想在输入值时更新 View ,现在我可以过滤,但只有当我滚动时才得到结果,它从 Controller 调用方法并在顶部显示结果,并且永远不会停止滚动,返回空行一旦结果结束。

我希望它在发生这种情况时停止,就像它在没有过滤器的情况下一样。

最佳答案

这是你想要的吗? -Plunker

标记

<input type="text" ng-model="search.id" ng-change="inputChange()">

JS

vm.infiniteItems = {
numLoaded_: 0,
toLoad_: 0,
items: [],

// Required.
getItemAtIndex: function(index) {
if (index > this.numLoaded_) {
this.fetchMoreItems_(index);
return null;
}

return this.items[index];
},

// Required.
getLength: function() {
return this.numLoaded_ + 3;
},

fetchMoreItems_: function(index) {
if (this.toLoad_ < index) {
this.toLoad_ += 10;
}
}
};

$scope.inputChange = function () {
console.log($scope.search.id);
fetcher.fetch($scope.search.id).then(angular.bind(this, function(obj) {
console.log(obj);
vm.infiniteItems = obj;
}));
}

关于javascript - 关于过滤器输入和重置索引的 ng-change 的 Material 虚拟重复更新列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39290748/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com