我正在尝试以下面的查询集形式从django中的item_id字段中提取model.py字段。
<QuerySet [<Item: Shoulder Bag Boys Shoulder Bag (Yellow )>,
<Item: Sweeter Cotton Sweeter>,
<Item: Shirt Full Sleeves Shirt>, <Item: Jacket Jackson Jacket>,
<Item: Yellow Shoes Leopard Shoes>,
<Item: Bag Mini Cary Bag>, <Item: Coat Overcoat (Gray)>,
<Item: TOWEL Pure Pineapple>,
<Item: Coat Pure Pineapple>, <Item: TOWEL Pure Pineapple (White)>]>这是我的JS代码
$.ajax({
type: 'GET',
url: '/shopsorting/' + selected_value,
// data: formData,
encode: true
})
.done(function(data) {
items = JSON.parse(data)
console.log(items)
for (var item in items) {
console.log(item['product_id'])
};但是它在控制台上打印
`(index):765
{items: "<QuerySet [<Item: TOWEL Pure Pineapple>, <Item: Ba…s Leopard Shoes>, <Item: Jacket Jackson
Jacket>]>"}
(index):767 undefined`发布于 2020-06-18 18:44:13
在接收数据之前尝试将数据转换为字符串:
x = JSON.stringify(data);
items = JSON.parse(x);别忘了;
$.ajax({
type: 'GET',
url: '\/shopsorting\/' + selected_value,
// data: formData,
encode: true,
success: function(data) {
x = JSON.stringify(data);
items = JSON.parse(x);
console.log(items);
for (var item in items) {
console.log(item['product_id'])
};
}});https://stackoverflow.com/questions/62457046
复制相似问题