我正在使用SimpleCart Javascript 库。
我想为id
每个产品添加一个,当用户进行结账时,这些id
也会被发送。
代替这些列,例如:
Name Price
book 5$
我也想有一Product Id
列包括:
Id Name Price
3 book 5$
我尝试将 插入id
到选项中,但我没有这样做。
有人可以给我看一个详细的例子吗?
我正在使用SimpleCart Javascript 库。
我想为id
每个产品添加一个,当用户进行结账时,这些id
也会被发送。
代替这些列,例如:
Name Price
book 5$
我也想有一Product Id
列包括:
Id Name Price
3 book 5$
我尝试将 插入id
到选项中,但我没有这样做。
有人可以给我看一个详细的例子吗?
可以这样设置:
在“cartColumns”下设置的simplecart中添加
{ attr: "id" , label: "ID" }
像这样:
cartColumns: [
{ attr: "image", label: "Item", view: "image"},
//Name of the item
{ attr: "name" , label: "Name" },
{ attr: "id" , label: "ID" },
//etc………
然后你可以使用:
<span class="item_id">ID:1</span>
或像这样:
simpleCart.add({ name: "Shirt" , price: 4, id: 1 });
它应该显示在您的列中。
根据文档示例item.get
,item.set
您应该能够设置自己的列。
var myItem = simpleCart.add({ productId: "A12", name: "Awesome T-Shirt" ,
price: 10 , size: "Small" });
myItem.get( "productId" ); // A12
myItem.set( "productId" , "C54" );
myItem.get( "productId" ); // C54
此外,每个项目都有一个内置 ID: simpleCart.Item.id()
var myItem = simpleCart.add({ name: "Shirt" , price: 4 });
myItem.id(); // "SCS-1"
创建自己的视图
您可以通过将视图设置为函数而不是字符串来为购物车创建自定义视图。该函数应采用两个参数,即该行的项目和您指定的列详细信息。
{ view: function( item , column ){ // return some html } , label: "My Custom Column" }