【问题标题】:Parse Server Query objectId解析服务器查询 objectId
【发布时间】:2017-11-29 20:34:42
【问题描述】:

我正在使用 Parse Server Javascript SDK 在我的 Web 应用程序中使用以下查询。控制台日志按预期向我提供了拉取信息的显示,但 objectId 显示“未定义”。

var query = new Parse.Query("myClass");
query.include("product");
query.find({

    success: function (results) {

        $scope.items = [];

        for (i = 0; i < results.length; i++) {

            var p = results[i].get("product");

            var item = {
                id: results[i].get("objectId"),
                barcode: p.get("barcode"),
                productName: p.get("name"),
                imageUrl: p.get("image"),
                desiredStock: results[i].get("desiredStock"),
            }

            $scope.items[$scope.items.length] = item;
            console.log(item);

        }

        $scope.$apply();
    },
    error: function (error) {
        console.log("Query Error: " + error.message);
    }
})

如何将 objectId 获取到 item.id 中?

【问题讨论】:

    标签: javascript jquery parse-platform parse-server


    【解决方案1】:

    你可以写:

    results[i].id
    

    这是使用 Parse JS SDK 获取 objectId 的最佳方式

    【讨论】:

      【解决方案2】:

      我已经想通了。有问题的行:

      id: results[i].get("objectId"),
      

      使用此命令:

      id: results[i]._getId(),
      

      【讨论】:

      • 或者根据 Juliens 的回答,哪个更干净。
      猜你喜欢
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 2016-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-10
      相关资源
      最近更新 更多