①两个对象数组,其中有属性相同,将这两个对象数组根据相同的属性组成一个新的对象数组
const mergedArray = res.body.map((obj1) => {
const obj2 = result.body.find((obj2) => obj2.licensePlate === obj1.licensePlate);
return Object.assign({}, obj1, obj2);
});
②根据对象数组中某属性,改变排序
const tempCarCardList = [...carCardList.value];
carCardList.value = [];
for (let i=0;i<tempCarCardList.length;i++){
if (tempCarCardList[i].consultationStatus === 'run') {
carCardList.value.unshift(tempCarCardList[i]);
} else {
carCardList.value.push(tempCarCardList[i]);
}
}
③遍历数组对象,找到其中属性与某响应式属性相同的项,将该项的另一属性赋值给另一响应式变量
// 遍历 recordType 数组,找到匹配的项
const matchedItem = recordType.value.find((item) => item.id === props.dataDetial.basicInformation.type);
// 如果找到匹配的项,则将对应的 typeName 赋值给 eventType
if (matchedItem) {
eventType.value = matchedItem.typeName;
}
④ 快速清空对象中每一个属性的属性值
Object.keys(currentCar).forEach((key) => (currentCar[key] = ''));
⑤存进localStorage的是[object object]无法取用
//存
window.localStorage.setItem('EMRSelectList', JSON.stringify(selectList.value));
//取
const selectList = ref(JSON.parse(window.localStorage.getItem('EMRSelectList')));