我有返回给我选项的功能:
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。我想知道如何访问选项 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"
}
潇潇雨雨
翻阅古今
相关分类