【发布时间】:2022-02-10 21:04:21
【问题描述】:
我正在使用带有复选框的平面列表,我想将所选项目的数据保存到数组中,但无法将数据保存到数组中
我的 json 响应
{
"tS_CT_CODE": "ELC",
"tS_TASK_CODE": "ELC001",
"tS_TITLE": "Light Problem",
"tS_TITLE_AR": "",
"tS_PRICE": 100.0,
"tS_STATUS": "A",
"tS_USER_ID": "",
"tS_SYSTEM_DATE": ""
}
我想将 tsPrice 保存在不同的数组中,将 tsTitle 保存在不同的数组中,我只能在 taskName 中保存 ts_title,如下所示如何将 ts_price 保存在不同的数组中?
这是我的复选框
const [toggleCheckBox, setToggleCheckBox] = useState([]);
<CheckBox
checked={toggleCheckBox.includes(item.tS_TITLE)}
onPress={() => handleListTap(item)}
/>
const handleListTap = async item => {
const taskName = [...toggleCheckBox];
const index = taskName.indexOf(item.tS_TITLE);
if (index > -1) {
taskName.splice(index, 1);
} else {
taskName.push(item.tS_TITLE);
}
console.log(taskName);
setToggleCheckBox(taskName);
// navigation.navigate('MaintenanceTimeSlot');
};
【问题讨论】:
-
“不同的数组”是什么意思?
-
like in taskName 只保存 ts_title 并创建其他数组,如 taskPrice 并保存 ts_Price
标签: arrays react-native checkbox react-native-flatlist react-functional-component