如何从此对象中检索Constituency_Name



如何从此对象中检索Constituency_Name

[{"Constituency_ID":148,"Constituency_Name":"NA-160"},
{"Constituency_ID":151,"Constituency_Name":"NA-163"},
{"Constituency_ID":149,"Constituency_Name":"NA-161"},
{"Constituency_ID":150,"Constituency_Name":"NA-162"}]
data: { Constituency_ID: Constituency_Name }, success: function (cities)
$('#Constituency_ID').html("");
$.each(cities, function (key, value) {
var a = cities.length;
var we= value[0].map(function (element, index) {
return element.Constituency_Name;
})
///parsedData
var select = document.getElementById('#Constituency_ID');
// var pos =value[0].Constituency_Name.indexOf("NA");
option = document.createElement('option'); 
option.text = we;
option.value = value[0].Constituency_ID;
$('#Constituency_ID').append(option);
});

}
});
}
var p = [{"Constituency_ID":148,"Constituency_Name":"NA-160"},{"Constituency_ID":151,"Constituency_Name":"NA-163"},{"Constituency_ID":149,"Constituency_Name":"NA-161"},{"Constituency_ID":150,"Constituency_Name":"NA-162"}]
var countryNameArray = p.map(function(element,index){
return element.Constituency_Name;
})
console.log(countryNameArray[0]) // prints NA-160

这应该可以解决您的问题

cities.forEach(function(element,index{
$('#Constituency_ID').append('<option>'+element.Constituency_Name+ '</option>')
}) 

如果您想为您的选择增加价值,请使用这个

cities.forEach(function(element,index{
$('#Constituency_ID').append('<option value='+element.Constituency_ID+'>'+element.Constituency_Name+ '</option>')
}) 

最新更新