【问题标题】:How to insert Reference by using Wix Code?如何使用 Wix 代码插入参考?
【发布时间】:2018-10-15 15:29:34
【问题描述】:

首先让我说我完全糊涂了。 所以我有 2 个集合 - CCDB 和 IDB CCDB有Champion ID的主键(field key:champId, type:text) 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,因此我无法手动插入引用。我怎样才能用代码解决这个问题? 谢谢。

【问题讨论】:

    标签: javascript jquery velo


    【解决方案1】:

    您的描述、代码和屏幕截图之间似乎没有什么区别。

    您的想法是正确的,因为您应该在 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 
    } 
    

    但就像我说的,您的描述与您的代码和屏幕截图所显示的不符,因此很难准确判断发生了什么。

    【讨论】:

      猜你喜欢
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多