你可以存储一个JSON,并使用该JSON的子数组。
if (data != "attachmentto") {
formData.append(data, this.recipe[data])
console.log('rec data ', data)}
else if (data == "attachmentto") {
console.log('rec data434 ', this.recipe.attachmentto)
var myObj = { name: this.recipe.attachmentto.name, age: 31, city: "New York" };
let kokos = JSON.stringify(myObj);
formData.append('attachmentto', kokos)
}
Django 后端:
class Video(models.Model):
objects = models.Manager()
title = models.CharField(max_length=80)
description = models.TextField(max_length=300)
picture = JSONField(encoder=None)
price = models.IntegerField(default=0)
url = models.URLField()
category = models.CharField(max_length=50)
subcategory = models.TextField(max_length=50)
attachmentto = JSONField(encoder=None)
user = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
并在后端API上返回结果:
{
"id": 174,
"title": "ads",
"description": "ads",
"picture": {
"name": "https://v3.vuejs.org/logo.png"
},
"price": 0,
"user": 1,
"rating_average": 0,
"attachmentto": {
"age": 31,
"city": "New York",
"name": [
"https://restdj.herokuapp.com/media/uploads/ftf_3_cJ0V7TF.png",
"https://restdj.herokuapp.com/media/uploads/ftf_3.jpg"
]
}
},
我称它为noicely(nicely)。请注意,我们发送了一个JSON,并且在该JSON中有一个数组
Kokos是为Django设计的完整JSON。
var myObj = { name: this.recipe.attachmentto.name, age: 31, city: "New York" };
let kokos = JSON.stringify(myObj);
formData.append('attachmentto', kokos)
上面的代码中,name为this.recipe.attachmentto.name的一个数组
这是该数组:
"name": [
"https://restdj.herokuapp.com/media/uploads/ftf_3_cJ0V7TF.png",
"https://restdj.herokuapp.com/media/uploads/ftf_3.jpg"
]