我正在研究自动完成以显示城市名称以及隐藏的城市 ID,
Posted
技术标签:
【中文标题】我正在研究自动完成以显示城市名称以及隐藏的城市 ID,【英文标题】:i'm working on the autocomplete for displaying the city name and also the city id in hidden, 【发布时间】:2018-06-02 18:45:28 【问题描述】:我得到的响应是:
0: id: "190", name: "Elurupadu"
1: id: "1230", name: "Sendhwa"
2: id: "1262", name: "Multai"
3: id: "1480", name: "Kherwara"
4: id: "2225", name: "Mandi"
5: id: "519", name: "Thamarassery"
6: id: "208", name: "Ayyampettai"
7: id: "5519", name: "Udaipur"
8: id: "26977", name: "Siddapura(Udupi)"
9: id: "1151", name: "Murthal"
10: id: "327", name: "Pillayarpatti"
11: id: "2022", name: "Siddapura"
12: id: "738", name: "Therthally"
13: id: "1112", name: "Chandigarh"
14: id: "2358", name: "Kadodra"
...............
我想将其转换为:
[ id: "960",name: "Elurupadu",
id: "1230",name: "Senhwa",
id: "1262",name: "Multai",
...
];
谁能帮我整理一下,我用的是javascript。
【问题讨论】:
Sorting an array of JavaScript objects的可能重复 您确定第一个给定的格式吗?可以是对象数组的控制台视图吗? 您应该删除您的问题并在它获得更多差评之前对其进行重组。我也无意中做了几次。你也应该提供你的意见!不仅仅是你得到的结果,毕竟这是你的输入,我们需要帮助编辑;)。 【参考方案1】:var dt=[];
dt.push(id: "190", name: "Elurupadu")
dt.push(id: "1230", name: "Sendhwa")
dt.push(id: "1262", name: "Multai")
dt.push(id: "1480", name: "Kherwara")
dt.push(id: "2225", name: "Mandi")
dt.push(id: "519", name: "Thamarassery")
dt.push(id: "208", name: "Ayyampettai")
dt.push(id: "5519", name: "Udaipur")
dt.push(id: "26977", name: "Siddapura(Udupi)")
dt.push(id: "1151", name: "Murthal")
dt.push(id: "327", name: "Pillayarpatti")
dt.push(id: "2022", name: "Siddapura")
dt.push(id: "738", name: "Therthally")
dt.push(id: "1112", name: "Chandigarh")
dt.push(id: "2358", name: "Kadodra")
//convert
var result=JSON.stringify(dt);
console.log(result);
/*["id":"190","name":"Elurupadu","id":"1230","name":"Sendhwa","id":"1262","name":"Multai","id":"1480","name":"Kherwara","id":"2225","name":"Mandi","id":"519","name":"Thamarassery","id":"208","name":"Ayyampettai","id":"5519","name":"Udaipur","id":"26977","name":"Siddapura(Udupi)","id":"1151","name":"Murthal","id":"327","name":"Pillayarpatti","id":"2022","name":"Siddapura","id":"738","name":"Therthally","id":"1112","name":"Chandigarh","id":"2358","name":"Kadodra"]
*/
【讨论】:
你好。但是当我对其进行字符串化时,它显示为 ex : ["id":190,"name":Elurupadu"....],但 id 和 name 它不应该在字符串中,只有它的值应该在字符串。请让我知道还有其他方法。 你可以试试这个方法 你的回应就是你想要的 我没找到你以上是关于我正在研究自动完成以显示城市名称以及隐藏的城市 ID,的主要内容,如果未能解决你的问题,请参考以下文章