Assuming this is for a ScrollList, when you update each button information during OnVerticalScroll is when you set each button .index to the corresponding entry in SpellList
Incomplete and rough as example for OnVerticalScroll
Lua Code:
self.ScrollBar:SetValue(offset)
self.offset = math.floor(offset / itemHeight)
local newOffset = self.offset or 0
for i = 1, #DeathKnightChatScrollFrame.buttons do
local index = newOffset + i
if not DeathKnightSpellList[index] then
break
end
local button = DeathKnightChatScrollFrame.buttons[i]
button.Text:SetText(DeathKnightSpellList[index].spelllink)
button.index = index -- self.index used to get the spell entry in OnClick
end