gpt4 book ai didi

javascript - RiotJS : How to cache values during loops?

转载 作者:行者123 更新时间:2023-12-03 06:29:14 26 4
gpt4 key购买 nike

我希望通过在 RiotJS 中的 each={} 循环期间缓存重复值来提高性能和可读性。有没有办法做到这一点,不会渲染该值和/或产生不必要的性能开销?

之前:

<my-tag>
<p each="{item in data}">
<b if="{item.style == 'b'}">{item.text}</b>
<i if="{item.style == 'i'}">{item.text}</i>
</p>
data = [
{"text": "bold me", "style": "b"},
{"text": "italicize me", "style": "i"}
];
</my-tag>

<!-- Renders <p><b>bold me</b></p> <p><i>italicize me</i></p> -->

之后:

<my-tag>
<p each="{item in data}">
{style=item.style}
{text=item.text}
<b if="{style == 'b'}">{text}</b>
<i if="{style == 'i'}">{text}</i>
</p>
data = [
{"text": "bold me", "style": "b"},
{"text": "italicize me", "style": "i"}
];
</my-tag>

<!-- Renders <p>b bold me <b>bold me</b></p> <p>i italicize me <i>italicize me</i></p> -->

jsfiddle

最佳答案

我想你想这样做:

<p each="{data}">
<b if="{style == 'b'}">{text}</b>
<i if="{style == 'i'}">{text}</i>
</p>

jsfiddle

关于javascript - RiotJS : How to cache values during loops?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38514280/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com