我正在使用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
}));
});
答案 0 :(得分:6)
我解决了我的问题。如果使用单向绑定,则md-virtual-repeat似乎无法正确回收项目(请注意我的标记中的my :: syntax)。毕竟看起来很明显。