濑亚美莉在线|伊人三级|久久久久青草大香线综合精品|四虎黄色|佳佳黑丝高跟极致调教

IndexedDB之設置光標方向(Setting Cursor Direction)

歡歡歡歡 發表于 2018-2-28 15:58

Setting Cursor Direction

備注:這里的光標方向常量已經換成了字符串。分別是這樣對應的:

IDBCursor.NEXT  對應的是 ‘next’

IDBCursor.NEXT_NO_DUPLICATE對應的是'nextunique'

IDBCursor.PREV對應的是'prev'

IDBCursor.PREV_NO_DUPLICATE對應的是'prevunique'

調用的時候如下:

var request = store.openCursor(null, 'prevunique'); 

There are actually two arguments to openCursor(). The first is an instance of IDBKeyRange and the second is a numeric value indicating the direction. These constants are specified as constants on IDBCursor as discussed in the querying section. Firefox 4+ and Chrome once again have different implementations, so the first step is to normalize the differences locally:

翻譯:

方法openCursor()實際上有兩個參數。第一個是IDBKeyRange實例,第二個是一個數字,指明前進的方向。這些常量被指定為IDBCursor上的常量,之前一節【光標查詢】討論過。再一次,FF4+和Chrome有不同的實現方式,因此第一步是兼容不同:

var IDBCursor = window.IDBCursor || window.webkitIDBCursor;

Normally cursors start at the first item in the object store and progress toward the last with each call to continue() or advance(). These cursors have the default direction value of IDBCursor .NEXT. If there are duplicates in the object store, you may want to have a cursor that skips over the duplicates. You can do so by passing IDBCursor.NEXT_NO_DUPLICATE into openCursor() as the second argument:

翻譯:

一般光標開始于對象存儲里的第一個條目,并且分別通過調用方法continue()和advance()想最后一個挺近。這些光標有默認的方向值IDBCursor .NEXT。假如有重復的,你可能想要有一個跳過重復的光標。你可以通過把IDBCursor.NEXT_NO_DUPLICATE傳入方法openCursor()作為第二個參數實現。

var store = db.transaction(“users”).objectStore(“users”), request = store.openCursor(null, IDBCursor.NEXT_NO_DUPLICATE); 

Note that the first argument to openCursor() is null, which indicates that the default key range of all values should be used. This cursor will iterate through the items in the object store starting from the first item and moving toward the last while skipping any duplicates. You can also create a cursor that moves backward through the object store, starting at the last item and moving toward the first by passing in either IDBCursor.PREV or IDBCursor.PREV_NO_ DUPLICATE (the latter, of course, to avoid duplicates). For example:

翻譯:

注意,方法openCursor() 的第一個參數是null,這表明默認的包含所有值的鍵值范圍被使用。這個光標將會遍歷對象存儲里面的對象,從第一個條目開始,跳過所有重復的,移動到最后一個。你也可以創建向后移動通過對象存儲的光標,從最后一個開始,移動到第一個,第二個參數可以傳IDBCursor.PREV或者IDBCursor.PREV_NO_ DUPLICATE(同理,厚著避免重復)。例如:

var store = db.transaction(“users”).objectStore(“users”), request = store.openCursor(null, IDBCursor.PREV);

When you open a cursor using IDBCursor.PREV or IDBCursor.PREV_NO_DUPLICATE, each call to continue() or advance() moves the cursor backward through the object store instead of forward.

翻譯:

當你使用IDBCursor.PREV或者IDBCursor.PREV_NO_DUPLICATE打開一個光標的時候,每一次對方法continue()或者advance() 的調用,都將光標向后移動穿越對象存儲而不是向前移動。