![](/img/trans.png)
[英]OnDemandGrid with dstore Tackable and Memory not showing complete data when data is set into it
[英]Dstore Memory filter returns empty data unless applying .forEach
我有一個“dstore/Memory”對象,聲明如下:
this.flightStore = new Memory({
data: flights,
idProperty: 'myId'
});
我想取回要顯示的過濾集合。 所以我寫這個:
var test = this.flightStore.filter({matchType:view});
這將返回一個“測試”對象,但“數據”字段為空。 然而,當我編寫相同的代碼但添加一個 forEach 函數時:
this.flightStore.filter({matchType:view}).forEach(function(flight) { ... }
這非常有效,我會一一取回過濾后的結果。 從那里我可以為我的過濾集合構建一個數組。 我很好奇為什么我的第一行不起作用,以及是否有辦法讓它工作而不必遍歷每個結果並手動構建我的數組。
謝謝!
filter
方法只應用一個過濾器,它不獲取數據。 forEach
方法獲取數據並將回調應用於它。 如果要在應用過濾器后獲取數據,請調用fetch
:
var dataPromise = this.flightStore.filter({matchType: view}).fetch();
如果您使用的是同步存儲 ( dstore/Memory
),則fetchSync
方法可用:
var testData = this.flightStore.filter({matchType: view}).fetchSync();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.