最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - 111 invalid type for key Pointer, expected *, but got string - Stack Overflow

programmeradmin2浏览0评论

I am saving a object I call action to Parse

and I am getting the following error:

111 invalid type for key bookPointer, expected *Book, but got string

The code I use is:

 action.set("bookPointer", "SPecEgZUhL");

 action.save(null, {
                success: function (data) {
                    // The object was saved successfully.
                    callback(true);
                },
                error: function (data,error) {
                    // The save failed.
                    // error is a Parse.Error with an error code and description.
                    console.log("Error: " + error.code + " " + error.message);
                    callback(false);
                }
            });

And my Book data looks like:

How do I get the pointer to my book, my *book in javascript?

Make sense to me that it should work fine with the objectId.

Thanks!

I am saving a object I call action to Parse.

and I am getting the following error:

111 invalid type for key bookPointer, expected *Book, but got string

The code I use is:

 action.set("bookPointer", "SPecEgZUhL");

 action.save(null, {
                success: function (data) {
                    // The object was saved successfully.
                    callback(true);
                },
                error: function (data,error) {
                    // The save failed.
                    // error is a Parse.Error with an error code and description.
                    console.log("Error: " + error.code + " " + error.message);
                    callback(false);
                }
            });

And my Book data looks like:

How do I get the pointer to my book, my *book in javascript?

Make sense to me that it should work fine with the objectId.

Thanks!

Share Improve this question asked May 9, 2013 at 8:17 ArcayneArcayne 1,1861 gold badge15 silver badges35 bronze badges 2
  • Does this work? action.set("bookPointer", { __type: "Pointer", className: "Book", objectId: "SPecEgZUhL" }); – Dogbert Commented May 9, 2013 at 8:50
  • @Dogbert, yes that works! Do you want to write it as an answer? – Arcayne Commented May 9, 2013 at 10:49
Add a ment  | 

2 Answers 2

Reset to default 8

A simpler/more strongly typed method would be:

// Assumes var Book = Parse.Object.extend("Book");
action.set("bookPointer", new Book({id: "SPecEgZUhL"}));

it's also not typically conventional to name columns after their type (e.g. "book" instead of "bookPointer")

As I said in the ment on the question, you can specify a pointer using a JS object like this in your case:

{
  __type: "Pointer",
  className: "Book",
  objectId: "SPecEgZUhL"
}

Final code bees:

action.set("bookPointer", { __type: "Pointer", className: "Book", objectId: "SPecEgZUhL" });

Found it on the examples given on this page - https://www.parse./docs/rest

发布评论

评论列表(0)

  1. 暂无评论