为什么要加入数组工作,但不能访问单个元素?

发布于 2025-01-24 20:54:18 字数 380 浏览 2 评论 0原文

我刚刚开始努力自定义我的Shopify模板,但是我遇到了一个基本问题,文档无济于事。

<script>console.log("_{{ item.properties | join: ", " }}_");</script>
// prints "_foo1, foo2_"

<script>console.log("_{{ item.properties[0] }}_");</script>
// prints "__"

<script>console.log("_{{ item.properties }}_");</script>
// prints "_EscapedHashDrop_"

谢谢!

I've just started working on customizing my Shopify template, but I've ran into a basic issue, where the docs didn't help.

<script>console.log("_{{ item.properties | join: ", " }}_");</script>
// prints "_foo1, foo2_"

<script>console.log("_{{ item.properties[0] }}_");</script>
// prints "__"

<script>console.log("_{{ item.properties }}_");</script>
// prints "_EscapedHashDrop_"

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千纸鹤带着心事 2025-01-31 20:54:18

您将在第一个控制台中获得字符串中的值,并尝试将值作为第二控制台中的数组获取,因此不可能

通过使用.split()函数在数组中转换字符串值。

尝试此代码,它将根据您提供结果。

var itemvalue = "_{{ item.properties | join: ", " }}_";
   // console.log(itemvalue); --->  print  "_foo1, foo2_"
    var myvalue = itemvalue.split(",");
    console.log(myvalue[0]);

you are getting value in string in first console and try to fetch value as a array in second console so it's not possible

you have to convert your string value in array by using .split() function.

Try this code it will give result according to you.

var itemvalue = "_{{ item.properties | join: ", " }}_";
   // console.log(itemvalue); --->  print  "_foo1, foo2_"
    var myvalue = itemvalue.split(",");
    console.log(myvalue[0]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文