javascript – Angular md-virtual-repeat指令正在搞乱项目顺序
作者:互联网
我正在使用Angular Material md-virtual-repeat指令来提高md-list中数千个项目的性能.
但是,当我向下滚动然后向上滚动时,根本不会保留顺序.一开始,我的项目按日期排序,没关系.当我开始滚动时,排序完全搞砸了.
这是我的标记:
<md-virtual-repeat-container class="flex flex-layout md-list indigo" ng-if="tracking.loaded">
<div md-virtual-repeat="marker in tracking.mapMarkers | orderBy: 'timestamp':true" class="md-list-item inset" style="height: 72.6px;">
<div class="md-list-item-content">
<h3 class="text-md">{{ ::marker.timestamp | time }}</h3>
</div>
</div>
</md-virtual-repeat-container>
而我的控制器:
self.mapMarkers = [];
...
// In a function which is called within a promise
_.each(_.without(_.reject(data.Positions, function(position){ return position.Id === currentPosition.Id; })), function (pos) {
var location = new google.maps.LatLng(pos.Latitude, pos.Longitude);
self.mapMarkers.push(new google.maps.Marker({
icon: {
url: "https://maps.gstatic.com/intl/en_us/mapfiles/markers2/measle_blue.png",
size: new google.maps.Size(12, 12),
anchor: new google.maps.Point(4, 4)
},
position: location,
address: pos.Address,
timestamp: pos.Timestamp,
map: self.map
}));
});
解决方法:
我解决了我的问题.如果使用单向绑定,则md-virtual-repeat似乎无法正确回收项目(请注意我的标记中的my :: syntax).毕竟看起来很明显.
标签:javascript,angularjs,angular-material 来源: https://codeday.me/bug/20190824/1706268.html