Parse(JS SDK)将图像数组保存为对象的属性

时间:2015-07-16 03:02:08

标签: javascript parse-platform associations

最终我想要的是什么:

我想拥有一张包含少量图像(最多10张)的产品。

我以为我会这样做:

// I have an "images" array of HTML5 File objects from an <input>

let parseImages = images.map( (image) => {
  return new Parse.File(image.name, image);
});


let product = new Product({
  name: name,
  price: price,
  description: description,
  images: parseImages
});

product.save()
  .then(
    (savedProduct) => {
      // I'm happy here with a saved Product that has an array of images
      // This did not happen
    },
    (error) => { 
      console.log('Error saving images: ', error.code, error.message) 
      // Sadly I didn't get here either
    }
  );

^那不起作用。

然后我尝试了这个......

let product = new Product({
  name: name,
  price: price,
  description: description
});

let parseImages = images.map( (image) => {
  return new Parse.File(image.name, image);
});

Parse.Object.saveAll(parseImages)
  .then(
    (savedImages) => {
      product.save()
        .then(
          (savedProduct) => {
            savedProduct.add('images', images);
            savedProduct.save()
              .then(
                (savedProductWithImages) => {
                  // still not getting here
                },
                (error) => {}
              );
          },
          (error) => { console.log('Error saving product: ', error.code, error.message) }
        );
    },
    (error) => { console.log('Error saving images: ', error.code, error.message) }
  );

这也不起作用。

每次我甚至没有做到承诺拒绝。我得到了......

Converting circular structure to JSON

错误。

知道我缺少什么吗?

0 个答案:

没有答案