我目前正在Wix上建立一个网站,遇到了一个我认为自己无法摆脱的问题。无论是Wix支持还是Wix Velo论坛都无法帮助我。
我有一个中继器,连接到Stores/Products集合,在Stores/Products集合中有一个集合字段,其中包含关于该产品的其他信息部分。我有三个信息部分:节奏,体裁和标签。每一个都包含一个描述。
看起来是这样的:
[
{
"title": "Tempo",
"description": "<p>142 BPM</p>\n"
},
{
"title": "Genre",
"description": "<p>Jazz</p>\n"
},
{
"title": "Tags",
"description": "<p>Frank Ocean, Travis Scott</p>\n"
}
]我已经知道了如何使用以下代码来提取各个对象:
export function audioRepeater_itemReady($item, itemData, index) {
let product = $item('#dataset3').getCurrentItem(itemData._id)
let ArrayAdditionalInfo = []
ArrayAdditionalInfo = product.additionalInfoSections
ArrayAdditionalInfo.forEach((element) => {
console.log(element.title)
console.log(element.description)
})但我希望它能弄清楚。标题为“===类型”,然后将显示来自该数组的描述,如下所示:
{
// if equal to this:
"title": "Genre",
// show me this
"description": "<p>Jazz</p>\n"
},整个计划是在我可以在中继器中实现的文本元素中显示描述输出。我试过用if语句,但我自己不能把它放在一起。如果这让我感到困惑的话,我很乐意详细说明。
提前谢谢你。
发布于 2021-03-12 10:51:51
我不能百分之百肯定我是否正确地理解了这个问题,但是如果您想显示所有的标题,并且如果标题是Genre,则有条件地使用三元:
let data = [{
"title": "Tempo",
"description": "142 BPM\n"
},{
"title": "Genre",
"description": "Jazz\n"
},{
"title": "Tags",
"description": "Frank Ocean, Travis Scott\n"
}];
data.forEach(e => $("#products").append(
`<p>Title: ${e.title}${
e.title === "Genre"
? "<br>description: " + e.description
: ""
}</p>`
));<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="products">
</div>
发布于 2021-03-19 17:06:37
我认为你的问题与处理程序有关。您使用中继器onItemReady处理程序,这不是您的情况下的最佳选择。它要求中继器中的每一行。相反,我建议使用dataset的onReady
$w("#dataset3").onReady( () => {
console.log("The dataset is ready");
$w("#audioRepeater").getItems(0, 20).then( (result) => {
let items = result.items;
items.forEach((element) => {
if (element.title === 'Genre') {
doWhatDoYouWant(element)
}
})
} ).catch( (err) => {
let errMsg = err.message;
let errCode = err.code;
} );
} );请考虑将此块插入到$w.onReady中
https://stackoverflow.com/questions/66598203
复制相似问题