Javascript 单数组到关联数组
我正在尝试构建一个 JavaScript,它将根据数组中的客户名称自动完成文本字段,但我还想为客户 ID 设置一个隐藏字段。我不确定如何构建一个关联数组来完成此任务。我找到了一堆用于自动完成的片段,但我正在努力解决如何构建数组并随后引用它来设置 2 个 html 标签:
<SCRIPT language="JavaScript">
function autocomplete(filter)
{
var filter = 1,one,2,two,3,three
}
</SCRIPT>
<input type='hidden' id='id' />
<input type='text' id='custname' -onKeypress='autocomplete();' />
编辑:我调用的函数有一个传递给它的单个数组来执行自动完成。因此,如果我能弄清楚如何从过滤器变量中的 Evens 构建一个新数组,并从 Odds 构建另一个数组,我应该没问题。
I'm trying to build a javascript that will autocomplete a textfield based off of a customer name in an array, but I would also like to set a hidden field to the customer ID. Im not sure how to build an associative array that will allow me to accomplish this. I've found a bunch of sniplets for autocomplete, but I'm struggling on how to build the array and subsequently referencing it to set 2 html tags:
<SCRIPT language="JavaScript">
function autocomplete(filter)
{
var filter = 1,one,2,two,3,three
}
</SCRIPT>
<input type='hidden' id='id' />
<input type='text' id='custname' -onKeypress='autocomplete();' />
Edit: The function I am calling has a single array passed to it to perform the autocomple. So If I can figure out how to build a new array from the the Evens and another from the Odds in the filter variable, I should be okay.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您要将
[1,one,2,two,3, Three]
转换为{one: 1, Two: 2, Three: 3}
:Assuming that you want to turn
[1,one,2,two,3,three]
into{one: 1, two: 2, three: 3}
:您可以在以下页面找到详细说明和示例:
关联数组
You can find detailed descriptions and examples on the following page:
Associative arrays