我有一个函数可以返回以下选项:
const codesList = () => {
return businessCodes.map((code, index) => {
return <option key={code.BusinessCode}>{code.IndustryName}</option>;
});
};
然后我有接受值的数据列表和输入字段:
<input
type="text"
className="filter-select-form-control"
placeholder="Enter Business Code"
id="business-code"
list="code-dataList"
autoComplete="off"
></input>
</div>
{/* DATALISTS CODES*/}
<datalist id="code-dataList">
{RightFilterFunction.codesList()}
</datalist>
之后,在获取输入字段值的函数中,出现以下情况:
const businessCode = document.getElementById("business-code").value;
通过这部分代码,businessCode 被准确地分配为 code.IndustryName。我想知道如何访问 options key={code.BusinessCode} 的这个关键属性。我希望为businessCode分配code.BusinessCode,但datalist保留为code.IndustryName。JSON(businessCodes 数组)的一部分,您会知道为什么我更喜欢将 IndustryName 可视化并将 BusinessCode 发送到端点:
{
BusinessCode: 111,
IndustryName: "Crop Production"
},
{
BusinessCode: 112,
IndustryName: "Animal Production and Aquaculture"
},
{
BusinessCode: 113,
IndustryName: "Forestry and Logging"
}
慕勒3428872
慕尼黑5688855
相关分类