【问题标题】:How to Insert value into main field in Wix Corvid如何在 Wix Corvid 的主字段中插入值
【发布时间】:2020-01-15 04:55:23
【问题描述】:

我在 Corvid 数据库中有事件表,它有 Event_Id 列,用于在表单中未向用户询问的每个新事件。

我使用下面的代码来获取行数并从现在运行良好的代码中生成 id:

    let count = 0;
  $w("#collection").onReady( () => {
     count = $w("#collection").getTotalCount(); // 23
       count++; 
  } );

$w('#btnSub').onClick( ()=>{
const newRequest = {
    eventid:('event_'+count),
    title: $w('#title').value
}
wixData.insert('event_instance', newRequest);

但是当我从集合中删除其中一行时,这可能会导致事件 ID 重复

你能找到解决办法吗?

谢谢

【问题讨论】:

标签: velo


【解决方案1】:

你需要在#myElementID中使用dropdowns

这类似于 SQL 中的this

if not exists (select * from Delegates d where d.FromYr = @FromYr and d.MemNo = @MemNo) INSERT INTO Delegates ([MemNo],[FromYr],[ToYr]) values(@MemNo, @FromYr,@ToYr)

其他参考this

【讨论】:

    【解决方案2】:

    有意义地在每次插入之前获取计数

    $w('#collection').onReady( () => {
      $w('#btnSub').onClick( () => {
        const count = $w('#collection').getTotalCount() + 1; // here
    
        wixData.insert('event_instance', {
          eventid: ('event_' + count),
          title: $w('#title').value
        });
      });
    });
    

    【讨论】:

    • 如果我添加 3 个项目,则计数为 3,如果我删除第二个元素,则计数为 2,我的两个事件将是事件 3 和事件 3
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 2013-11-23
    • 1970-01-01
    相关资源
    最近更新 更多