我无法获得集合中记录的总数 - Wix 代码

I'm unable to get the total count of records in a collection - Wix Code

我正在尝试使用下面显示的代码获取 Wix 集合中的记录总数:

wixData.query("Client").count().then((num) => {
              clientTableIndex = num;
          }).catch((error) => {
              let errorMsg = error.message;
              let code = error.code;
              console.log("@Public IndexOf().");
              console.log(code + ": " + errorMsg);
          });

但出于某种原因,它没有给我计数,也没有显示任何错误。我也试过像这样使用 find()

wixData.query("Client")
                .find()
                .then((num) => {
                    clientTableIndex = num.totalCount;
                }).catch((error) => {
                    let errorMsg = error.message;
                    let code = error.code;
                    console.log(code + ": " + errorMsg);
                });
            console.log(clientTableIndex);
            let insertToClient = {
                "memberId": wixUsers.currentUser.id,
                "title": "Client0".concat(clientTableIndex + 1)

但还是没有运气。我已授予对 wix 数据库中的集合 Client 的完全权限。见下文:

此刻我有点卡住了。我敢肯定,我遗漏了什么,导致了这个问题。

任何帮助将不胜感激。

第一种方法正确。您正在将数字设置为变量,这可能是您不是 "seeing" 数字的原因。

将其设置为文本值或控制台记录如下所示以查看计数

wixData.query('Client').count().then( (num) => {
    console.log(num);
    $w("#text1").text = "" + num;   
});