Parse.com创建指针对象时出错

时间:2015-12-23 10:04:25

标签: javascript android database parse-platform

我想用ObjectID创建一个Item类的指针对象。我不想将此指针对象用作OrderDetails的字段。看看下面的代码

        var arr = [];
        var jsonData = JSON.parse(orderList);
        for (var i = 0; i < jsonData.length; i++) {
            var counter = jsonData[i];

            var orderDetail = new Parse.Object("OrderDetails");
            orderDetail.set("quantity",counter.qty);

            var Item = Parse.Object.extend("Item");
            var pointerToItem = new Item();

            pointerToItem.id = counter.id;

            orderDetail.set("which_item",Item);
            orderDetail.set("which_order",myOrder);
            orderDetail.set("isProcessed",false);

            arr.push(orderDetail)    
        }

当我尝试运行此循环时,我收到此错误:

错误:无法创建指向未保存的ParseObject的指针

我尝试使用以下代码在Android中执行相同的操作

List<ParseObject> objectList = new ArrayList<>();

for (int i = 0; i < buyItems.size(); i++) {
ParseObject orderDetailObj = new ParseObject("OrderDetails");
orderDetailObj.put("quantity", item.getQty());
orderDetailObj.put("which_item", ParseObject.createWithoutData("Item", item.getId()));
orderDetailObj.put("which_order", ParseObject.createWithoutData("Order", orderObj.getObjectId()));
orderDetailObj.put("isProcessed", false);


objectList.add(orderDetailObj);
}

android代码正常工作,你能告诉我我需要做些什么才能使android的东西在解析云javascript中工作?

1 个答案:

答案 0 :(得分:0)

喜欢这个

var itemPointer = {
  __type: 'Pointer',
  className: 'Item',
  objectId: counter.id
}

设置为
orderDetail.set("which_item",itemPointer );