selectedRows[{"Status":"备货撤销","ProName":"铜板标签","PlanDate":"2022-02-10","PlanId":"CGDD-220210002","keyid":1,"Quantity":25,"NotificationTime":null,"DeliveryDate":"","ProPlanId":"","TimeStamp":null,"PushStatus":null,"OrgId":"1 ","ProStyle":"","ProType":"100*140","ReceiptStatus":null,"Id":1}]这个是打印结果,那我只想要PlanId对应的值,我应该怎么去取
时间: 2023-07-24 21:14:52 浏览: 59
如果你只想获取 `selectedRows` 中 `PlanId` 的值,可以通过访问 `selectedRows[0].PlanId` 来获取。因为 `selectedRows` 是一个数组,你可以使用索引 `[0]` 来访问数组中的第一个元素,然后再使用 `.PlanId` 来获取 `PlanId` 的值。
以下是示例代码:
```javascript
const planId = selectedRows[0].PlanId;
console.log(planId); // 打印 PlanId 的值
```
请注意,上述代码假定 `selectedRows` 数组中至少有一个元素。如果不确定 `selectedRows` 数组是否为空或是否有多个元素,最好进行相应的检查和处理,以确保代码的稳定性。
希望能对你有所帮助!
相关问题
selectedRows[{"Status":"备货撤销","ProName":"铜板标签","PlanDate":"2022-02-10","PlanId":"CGDD-220210002","keyid":1,"Quantity":25,"NotificationTime":null,"DeliveryDate":"","ProPlanId":"","TimeStamp":null,"PushStatus":null,"OrgId":"1 ","ProStyle":"","ProType":"100*140","ReceiptStatus":null,"Id":1},{"Status":"备货撤销","ProName":"铜板标签","PlanDate":"2022-02-11","PlanId":"CGDD-220211002","keyid":2,"Quantity":33,"NotificationTime":null,"DeliveryDate":"","ProPlanId":"","TimeStamp":null,"PushStatus":null,"OrgId":"1 ","ProStyle":"","ProType":"100*140","ReceiptStatus":null,"Id":1}]那这样多数组的我不明确里面到底是几个PlanId,我需要都取出来
如果你不确定 `selectedRows` 数组中有多少个元素,但想要获取所有的 `PlanId` 值,你可以使用循环来遍历 `selectedRows` 数组,并将每个元素的 `PlanId` 值存储到一个新的数组中。以下是一个示例代码:
```javascript
const selectedRows = [
{"Status":"备货撤销","ProName":"铜板标签","PlanDate":"2022-02-10","PlanId":"CGDD-220210002","keyid":1,"Quantity":25,"NotificationTime":null,"DeliveryDate":"","ProPlanId":"","TimeStamp":null,"PushStatus":null,"OrgId":"1 ","ProStyle":"","ProType":"100*140","ReceiptStatus":null,"Id":1},
{"Status":"备货撤销","ProName":"铜板标签","PlanDate":"2022-02-11","PlanId":"CGDD-220211002","keyid":2,"Quantity":33,"NotificationTime":null,"DeliveryDate":"","ProPlanId":"","TimeStamp":null,"PushStatus":null,"OrgId":"1 ","ProStyle":"","ProType":"100*140","ReceiptStatus":null,"Id":1}
];
const planIds = selectedRows.map(row => row.PlanId);
console.log(planIds); // 打印所有的 PlanId 值
```
在上述代码中,我们使用 `map` 方法遍历 `selectedRows` 数组,并提取每个元素的 `PlanId` 值,将其存储到 `planIds` 数组中。最后,我们打印出 `planIds` 数组,其中包含了所有的 `PlanId` 值。
希望这能解决你的问题!
vue3中这个写法哪错了watchEffect(() => { let toStatus = switch (mulAction.value) { case "启动": return "1" case "停止": return "2" case "删除": return "3" } taskListStore.changeStatus({ ids: selectedRows.value, to_status: toStatus, }).then(response => { console.log(response) }).catch(error => { console.log(error) }) })
在你提供的代码中,有一个语法错误导致了错误。问题出现在 `let toStatus = switch (mulAction.value) {` 这一行。
在Vue 3中,`switch` 语句的语法应该是 `switch (expression) { case value: ... }`。你需要将 `switch` 关键字放在括号内,并将变量 `mulAction.value` 作为 `expression`。同时,你还需要添加一个 `default` 分支来处理未匹配到的情况。
以下是修正后的代码示例:
```javascript
watchEffect(() => {
let toStatus;
switch (mulAction.value) {
case "启动":
toStatus = "1";
break;
case "停止":
toStatus = "2";
break;
case "删除":
toStatus = "3";
break;
default:
// 处理未匹配到的情况
break;
}
taskListStore.changeStatus({
ids: selectedRows.value,
to_status: toStatus,
}).then(response => {
console.log(response);
}).catch(error => {
console.log(error);
});
});
```
修正后的代码将 `switch` 语句放在正确的语法结构内,并将 `toStatus` 声明在外部作用域中。同时,你可以根据需要添加 `default` 分支来处理未匹配到的情况。
阅读全文