gpt4 book ai didi

javascript - 如何使用Wix代码插入引用文献?

转载 作者:行者123 更新时间:2023-12-03 00:56:22 26 4
gpt4 key购买 nike

首先我要说的是我完全困惑了。所以我有 2 个集合 - CCDB 和 IDBCCDB有冠军ID的主键(字段键:champId,类型:文本)IDB 有一个主键 DeviceName(field:title, type:text) 和一个引用字段 Champion ID(field key: champId, type: reference)。因此,IDB 集合中的 n 个项目属于 CCDB 集合中的 1 个项目。

现在,当我使用下面的代码将数据插入 IDB 集合时,数据库显示一条红色下划线:“单元格值类型为数字。更改为引用。”

**下面是wix代码

getitems("pc").then(res => {
let toInsert = {
"title": res[i].champion_id, //reference to CCDB
"description": res[i].Description,
"deviceName": res[i].DeviceName,
"itemId": res[i].ItemId
}
wixData.insert("IDB", toInsert)
.then(results => {
let item = results;
console.log(item);
})
.catch(err => {
let errorMsg = err;
console.log(errorMsg);
});
})

In IDB collection after insert operation

CCDB holding the correct champId

"title":  (res[i].champion_id).toString(),

我也尝试在这里使用 toString,但集合随后显示错误:“引用已损坏”。

我搜索了文档并找到了 wixData.insertReference().. 但我不确定如何在这种情况下使用该方法,或者即使可以使用。由于 IDB 中的项目数量将超过 100,因此我无法手动插入引用。我该如何用代码解决这个问题?谢谢。

最佳答案

您的描述、代码和屏幕截图之间似乎有些不一致。

您的想法是正确的,因为您应该在 IDB 集合的引用字段中使用 CCBD 集合中的 ID,但您似乎没有正确执行此操作。

根据您的描述,您似乎需要这样的东西:

let toInsert = {
"title": res[i].DeviceName,
"description": res[i].Description,
"champId": res[i].champId, // this is the reference field, not title
"itemId": res[i].ItemId
}

但是就像我说的,您的描述与您的代码和屏幕截图似乎显示的内容不符,因此很难确切地说出发生了什么。

关于javascript - 如何使用Wix代码插入引用文献?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52820065/

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