sapui5本地存储购物车演示

时间:2019-05-04 15:02:52

标签: javascript arrays local-storage sapui5

我正在努力使用sapui5本地存储库和使用此功能(https://openui5.hana.ondemand.com/test-resources/sap/m/demokit/cart/webapp/index.html)的购物车演示应用程序。

我正在举一个简单的例子,将文章放入本地存储。当您继续购物并将其他商品添加到购物篮时,也应将其放入本地存储中。但我得到的是,只有最后一项在存储中。有什么提示吗?我正在使用sap演示的某些部分,但它对我不起作用。

这是将商品放入本地存储区的编码。

我像演示中一样尝试了它。可以找到here

var sProductKey = oData.productkey;
var sQuantity = this.byId("inpQuantity").getValue();

var oMySc = [{                  // this is the current item
            productKey: sProductKey,
            quantity: sQuantity
        }];


// in the collectionEntries object, the old items are getting loaded
var oCollectionEntries = [];
var oCartModel = this.getOwnerComponent().getModel("cartProducts");
oCollectionEntries = Object.assign({}, oCartModel.getData()["cartEntries"]);


var oCartEntry = Object.assign({}, oMySc);
oCollectionEntries[oCartEntry] = oCartEntry;

//oCart Model refers to the local Storage functions
oCartModel.setProperty("/cartEntries", Object.assign({}, oCollectionEntries));
oCartModel.refresh(true);

1 个答案:

答案 0 :(得分:0)

不能只是尝试做这样的事情吗?

oCollectionEntries.push(oCartEntry);
相关问题