Get next item in a collection?

17 views
Skip to first unread message

Bo An

unread,
Dec 4, 2021, 6:43:01 PM12/4/21
to zotero-dev
Hello all,

I was hoping to programatically select the next item in the current collection. 

I see that the active Zotero pane has a getSortedItems() method that returns ordered items in the collection. But I don't know how to get the index of the current item (so I can move to the next). 

Should I do findIndex myself or is there a native function to get the index of the selected item, if not the next item directly?

Thank you!


Bo An

unread,
Dec 4, 2021, 8:20:36 PM12/4/21
to zotero-dev
I eventually came up with this for those who might need to do the same.


const pane = Zotero.getActiveZoteroPane()

const items = pane.getSortedItems() 
const selectedItem = pane.getSelectedItems()[0];

const selectedItemId = selectedItem.id;


const currentIndex = items.findIndex(i => {
    return i.id === selectedItemId
})
const nextItem = items[currentIndex + 1]

if (nextItem) {
    pane.selectItem(nextItem.id)
} else {
    return;
}


Reply all
Reply to author
Forward
0 new messages