SimpleCart附加信息与自定义列

SimpleCart additional information with custom columns

本文关键字:自定义 信息 SimpleCart      更新时间:2023-09-26

我正在使用SimpleCart Javascript库。

我想为每个产品添加一个id,当用户进行结帐时,这些id也将被发送。

代替这些列,例如:

Name   Price
book   5$

我想有一个Product Id列也包括:

Id   Name   Price
3    book   5$

我已经尝试将id插入到选项中,但是我没有这样做的运气。

谁能给我一个详细的例子吗?

可以这样设置:

在你的simplecart设置"cartColumns"下添加

{ 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.getitem.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"

你也可以为你自己的ID创建一个自定义视图。

创建自己的视图

您可以为购物车创建自定义视图将视图设置为函数而不是字符串。这个函数应该接受两个参数,该行的项和列您指定的详细信息。

{ view: function( item , column ){
        // return some html
  } ,
  label: "My Custom Column" 
}