当客户单击“我的购物车”按钮时,我正在尝试使用ajax从服务器提取购物车项目,以将其显示在购物车中。购物车型号:
bbox_inches=0
以下是该项目的模型:
from numpy import random
import matplotlib.pyplot as plt
data = random.random((5,5))
img = plt.imshow(data, interpolation='nearest')
img.set_cmap('hot')
plt.axis('off')
plt.savefig("test.png", bbox_inches=0)# <= this is where the difference is for newer maptlotlib.
该视图中的代码用于从服务器提取购物车项目:
3.0.3
public class Cart
{
[Key]
public int RecordID { get; set; }
public string CartID { get; set; }
public int ItemID { get; set; }
public int Count { get; set; }
public int ItemPrice { get; set; }
public System.DateTime DateCreated { get; set; }
public virtual Item item { get; set; }
}
如下:
public class Item
{
[Key]
public int ItemID { get; set; }
public virtual Category Category { get; set; }
public virtual Brand Brand { get; set; }
public int CategoryID { get; set; } //Category ID
public int BrandID { get; set; }
public string ItemCode { get; set; }
public string ItemName { get; set; }
public string BrandName { get; set; }
public string CategoryName { get; set; }
public string SubCategoryName { get; set; }
public string FurtherCategoryName { get; set; }
public int? ItemPrice { get; set; }
[DataType(DataType.ImageUrl)]
public string ImageUrl { get; set; }
}
一切正常,即,如果购物车内有4件物品,则上述代码已成功将它们从服务器中拉出。只是无法弄清楚我需要如何在ajax返回函数中一一对应于那些项目。
请有人指导。谢谢
答案 0 :(得分:1)
您应该为.each方法放置参数索引和项目。
$.each(data.CartItems, function (index, item) {
let price = item.ItemPrice;
let brand = item.item.BrandName;
let itemname = item.item.ItemName;
// append p tag here
$(".cartdiv").append('<p>' + itemname + '</p>');
});