javascript-objects - 购买后更新库存
问题描述
我有一个对象数组,这意味着我从数据库中获取了多个项目(产品)。我想在网站购买所有产品购买库存后更新,从“nimcar”字段下载 1 我可能无法访问这些对象。
我把代码整理成一个完整的代码。这是收到付款后在最后一页发生的过程,我想更新产品的库存。我在这里介绍的过程是从列出订单名称的数据库中,从包含它购买的产品的参考字段中获取,这些产品在采购篮中,并且采购篮有一个包含产品 ID 的参考字段。我正在考虑获取产品ID的过程 Hhazmana.muzarim.muzarim._id 然后将ID更新为'nimcar'-1字段
$w.onReady(function () {
var id = $w("#dynamicDataset").getCurrentItem()._id;
wixData.queryReferenced("hazmanot", id, "muzarim")
.then((results) => {
if (results.items.length > 0) {
var firstItem = results.items
console.log(firstItem );
var myObj, i;
myObj = firstItem
for (i in myObj.muzarim) {
var id2 = myObj.muzarim
// console.log(id2);
wixData.get("muzarim", id2)
.then((item) => {
item.nimcar = Number(item.nimcar - 1)
wixData.update("muzarim", item)
.catch((err) => {
let errorMsg = err;
})
});
}
} else {
}
});
});
这就是它为我打印的方式:
0: "{\"muzarim\":\"7c3e8acd-a7a9-4819-b687-8b1ca06a984b\",\"_id\":\"53904a0d-c3b6-4337-b09d-b779fb0aea1e\",\"_owner\":\"ae269d04-1741-4200-bc92-2e27c7d549cd\",\"hazmanot\":\"af7ba985-f2ed-4bcf-a033-51e36b9298c1\",\"_createdDate\":\"2019-11-21T15:05:03.590Z\",\"lakoh\":\"e005f170-edcf-4694-80b7-496ab3534643\",\"_updatedDate\":\"2019-11-21T15:05:03.590Z\",\"sach\":1,\"camut\":1,\"title\":\"בית מזוזה\"}"
1: "{\"muzarim\":\"e29358d3-a74b-410a-8b41-44679f70ad05\",\"_id\":\"05b7540e-85c6-4eaa-b86b-6f4a466ed57e\",\"_owner\":\"ae269d04-1741-4200-bc92-2e27c7d549cd\",\"hazmanot\":\"3cd1eec3-c586-47b2-a1d4-2b4671c0dd2e\",\"_createdDate\":\"2019-08-21T13:43:38.884Z\",\"lakoh\":\"e005f170-edcf-4694-80b7-496ab3534643\",\"_updatedDate\":\"2019-08-21T13:43:38.884Z\",\"sach\":1200,\"camut\":1,\"title\":\"יין הסיומים\"}"
2: "{\"muzarim\":\"17a8e414-aaeb-4b0f-ae49-a4e5107ad132\",\"_id\":\"6fb545da-ac30-4304-92f9-930b49f87039\",\"_owner\":\"ae269d04-1741-4200-bc92-2e27c7d549cd\",\"hazmanot\":\"2894c50d-07e8-467e-b0f5-a37889a99fad\",\"_createdDate\":\"2019-08-21T13:41:19.197Z\",\"lakoh\":\"e005f170-edcf-4694-80b7-496ab3534643\",\"_updatedDate\":\"2019-08-21T13:41:19.197Z\",\"sach\":7200,\"camut\":1,\"title\":\"סט קדושת יצחק\"}"
3: "{\"muzarim\":\"17a8e414-aaeb-4b0f-ae49-a4e5107ad132\",\"_id\":\"a5ac5af4-03ee-4b88-9929-dc69e9dc0e04\",\"_owner\":\"ae269d04-1741-4200-bc92-2e27c7d549cd\",\"hazmanot\":\"993ed276-f7e1-4741-a038-69ad2b50cc91\",\"_createdDate\":\"2019-08-21T13:40:02.242Z\",\"lakoh\":\"e005f170-edcf-4694-80b7-496ab3534643\",\"_updatedDate\":\"2019-08-21T13:40:02.242Z\",\"sach\":7200,\"camut\":1,\"title\":\"סט קדושת יצחק\"}"
解决方案
推荐阅读
- elixir - Graphql 查询测试在 Phoenix 中没有正确返回结果
- flask - 'dict' 对象在创建数据源时不支持在 Airflow 中建立索引
- regex - 使用 Regex C# 过滤和搜索
- c# - 使用 SqlBulkCopy 查询
- php - JQuery - PHP Laravel DataTables - 不显示数据
- javascript - ctx.fillRect 不是函数
- vb.net - 使用 OleDb 自动递增 ID 到 excel
- html - 我的网页正在从本地服务器打开,但打开外部超链接后无法正常工作
- sql - 使用 docker-compose 在 Windows Container 中为 sql db 创建命名卷时,如何消除无效的卷规范错误?
- java - 为什么Spring从SCM Check Out Maven Projects时会报错(can't rename...)?