gpt4 book ai didi

ractivejs - 确定 ractive 模板中的最后一个循环索引

转载 作者:行者123 更新时间:2023-12-01 09:58:32 26 4
gpt4 key购买 nike

基本上我想要这个:In Mustache templating is there an elegant way of expressing a comma separated list without the trailing comma?在 Ractive 模板中。

对于对象

{
"items": [
{"name": "red"},
{"name": "green"},
{"name": "blue"}
]
}

我要生产“红、绿、蓝”
我想知道我是否在最后一项,所以我可以知道是否打印分隔符。比如:

{{#items:i}}{{name}} {{#i.is_last}},{{/i}}{{/items}}  

最佳答案

目前无法轻松测试,但不会像以下那样工作吗?

{{#items:i}}
{{name}} {{ i < (items.length-1) ? "," : "" }}
{{/items}}

关于ractivejs - 确定 ractive 模板中的最后一个循环索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20589099/

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