在How to use IndexedDB count method with composite keys?我學會了如何過濾單個屬性。到目前爲止,這麼好,但現在我需要同時進行排序和篩選。有沒有一種方法在indexedDB中使用複合/複合鍵進行排序?
我的對象存儲充滿了這些對象:
os.put({feed_id:1,id:1,title:"foofoo",time:111});
os.put({feed_id:1,id:2,title:"foobar",time:112});
os.put({feed_id:1,id:3,title:"foobaz",time:113});
os.put({feed_id:3,id:1,title:"bazfoo",time:114});
os.put({feed_id:3,id:2,title:"bazbar",time:115});
os.put({feed_id:3,id:3,title:"bazbaz",time:116});
os.put({feed_id:1,id:4,title:"foofoo",time:122});
os.put({feed_id:1,id:5,title:"foobar",time:121});
os.put({feed_id:1,id:6,title:"foobaz",time:120});
os.put({feed_id:3,id:4,title:"bazfoo",time:119});
os.put({feed_id:3,id:5,title:"bazbar",time:118});
os.put({feed_id:3,id:6,title:"bazbaz",time:117});
我有兩個指標對對象存儲,一個(idx_feedid)設置具有的keyPath feed_id
,這讓我獲得所有與特定的對象使用openCursor提供ID,使用keyPath ["id","feed_id","time"]
提供一個(idx_ts)。
問題是迭代idx_feedid的結果給我的結果沒有在時間戳上排序。在SQL中,我很容易做到SELECT * FROM feeditems WHERE feed_id=3 ORDER BY time DESC
,但在IndexedDB中如何做到這一點?
我該如何限制返回的結果以實現分頁?實質上,我需要類似MySQLs LIMIT 0,10
/LIMIT 10,10
/...
[在IndexedDB中,是否有一種方法可以進行排序的複合查詢?](http://stackoverflow.com/questions/12084177/in-indexeddb-is-there-a-way-to-make -a-sorted-compound-query) – Josh