gpt4 book ai didi

javascript - 如何使用 '+' 连接 JSON 数据中的字符串?

转载 作者:行者123 更新时间:2023-11-28 01:02:17 24 4
gpt4 key购买 nike

我有这样的代码:

jQuery.each(images, function (k, v) {
v = v.split(':');

data.questions.push({
source: questionAssetPath + v[0],
match: v[1],
mouse: mouseAssetPath + v[2] + '.png'
});

data.answers.push({
answer: v[1],
match: v[1]
});
});

当我运行 grunt 任务 (browserify:js) 时,出现此错误:

ParseError: Unexpected token +

请帮我解决这个问题。

谢谢你。

更新:我自己已经解决了。多谢你们。我注意到我无法对对象使用 + 运算符(wtf 与我一起)

images = [
"maria-ozawa.png:MariaOzawa:1",
"aoi-125239.png:Aoi:2",
"sasha-grey.png:SashaGrey:3"
];

jQuery.each(images, function (k, v) {
v = v.split(':');
v[0] = questionAssetPath + v[0];
v[2] = mouseAssetPath + v[2] + '.png';
data.questions.push({source: v[0], match: v[1], mouse: v[2]});
data.answers.push({answer: v[1], match: v[1]});
});

最佳答案

 Query.each(images, function (k, v) {
v = v.split(':');
questionAssetPath = questionAssetPath.concat(v[0])
data.questions.push({source: questionAssetPath, match: v[1], mouse: mouseAssetPath + v[2] + '.png'});
data.answers.push({answer: v[1], match: v[1]});
});

这将消除使用“+”的需要并解决错误

请参阅JavaScript String concat() Method

关于javascript - 如何使用 '+' 连接 JSON 数据中的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25482042/

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