S
SolidJS6mo ago
qdwang

Can i set a temp variable in template?

For example, if I have a for loop and each item is an object, can i set a variable to a part of the iterating object?
<Index each={bigList()}>{(item, i) =>
// access item().aaa.bbb.ccc.zzz
// access item().aaa.bbb.ccc.xxx
// access item().aaa.bbb.ccc.ccc
// access item().aaa.bbb.ccc.vvv
// access item().aaa.bbb.ccc.bbb
// access item().aaa.bbb.ccc.nnn

// can i set `item().aaa.bbb.ccc` to a temp variable?
}
</Index>
<Index each={bigList()}>{(item, i) =>
// access item().aaa.bbb.ccc.zzz
// access item().aaa.bbb.ccc.xxx
// access item().aaa.bbb.ccc.ccc
// access item().aaa.bbb.ccc.vvv
// access item().aaa.bbb.ccc.bbb
// access item().aaa.bbb.ccc.nnn

// can i set `item().aaa.bbb.ccc` to a temp variable?
}
</Index>
2 Replies
Madaxen86
Madaxen866mo ago
You can create a getter function like const ccc = () => item().aaa.bbb.ccc This way you don’t lose reactivity.
qdwang
qdwangOP6mo ago
Thank you, that very helpful
Want results from more Discord servers?
Add your server