简体   繁体   中英

Adding keys to objects in a parse object

Im working with the parse javascript sdk and i want to add a key to an object in a Parse 'object' when saving it.

For ex:

var saveGif = new SaveGifTags();
saveGif.save({
    type: req.body.type,
    tag: req.body.tags[i],
    gifObjects: newGif
 }, {
     success: function(data) {
          console.log(data);
          res.json(data);
     },

     error: function(data) {
          console.log(data);
      }
});

gifObjects is my object in the Parse Class. I tried to do something like this

gifObjects: gifOjects[gifObj.id] = newGif;

newGif of course is the object i want to save. This gave me an error of gifObjects is not defined. So i tried something like this

gifObjects[gifObj.id] : newGif;

that didnt work either. i want to create something like this:

{
    hgs32: {
        url: '',
        image: ''
    }, 

    64522 : {
        url: '',
        image: ''
    }
 }

any suggestions?

Figured it out. Not sure what the downvote is for, but i had to create the object before i saved it.

var gifObjects = {};
gifObjects[gifObj.id] = newGif;

and then the save

saveGif.save({
    type: req.body.type,
    tag: req.body.tags[i],
    gifObjects: gifObjects
 }, 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM