<script language="javascript" type="text/javascript">
function GetCityList()
{
var Province=document.getElementById("dropProvince");
auto_shop_CompanyInfo.GetCityByname(Province.value,CityCallBack);
}
function CityCallBack(response)
{
debugger;
if(response.value !=null)
{
var drcity=document.getElementById("dropCity");
var arrList = response.value;
drcity.length=0;
drcity.options.add(new Option("选择城市",""));
for(var i=0;i<arrList.length;i++)
{
var city_text=arrList[i]["city"];//这里获得的总是undefined
var city_value=arrList[i]["city"];//这里获得的总是undefined
drcity.options.add(new Option(city_text,city_value));
}
}
}
</script>
arrList 里确定是有值的,只是这个是从xml里读出的数据,arrList[i]["city"]city这里不清楚怎么取值?
[AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
public List<string> GetCityByname(string name)
{
List<string> listcity = new List<string>();
loadxml();
System.Xml.XmlNodeList List = xmldoc.SelectSingleNode("country").ChildNodes;
foreach (System.Xml.XmlNode xn in List)
{
System.Xml.XmlElement xe = (System.Xml.XmlElement)xn;
if (xe.GetAttribute("name") == name)
{
System.Xml.XmlNodeList listnode = xe.ChildNodes;
foreach (System.Xml.XmlNode xc in listnode)
{
System.Xml.XmlElement xce = (System.Xml.XmlElement)xc;
string cityname = xce.GetAttribute("name");
listcity.Add(cityname);
}
}
}
return listcity;
}
function GetCityList()
{
var Province=document.getElementById("dropProvince");
auto_shop_CompanyInfo.GetCityByname(Province.value,CityCallBack);
}
function CityCallBack(response)
{
debugger;
if(response.value !=null)
{
var drcity=document.getElementById("dropCity");
var arrList = response.value;
drcity.length=0;
drcity.options.add(new Option("选择城市",""));
for(var i=0;i<arrList.length;i++)
{
var city_text=arrList[i]["city"];//这里获得的总是undefined
var city_value=arrList[i]["city"];//这里获得的总是undefined
drcity.options.add(new Option(city_text,city_value));
}
}
}
</script>
arrList 里确定是有值的,只是这个是从xml里读出的数据,arrList[i]["city"]city这里不清楚怎么取值?
[AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
public List<string> GetCityByname(string name)
{
List<string> listcity = new List<string>();
loadxml();
System.Xml.XmlNodeList List = xmldoc.SelectSingleNode("country").ChildNodes;
foreach (System.Xml.XmlNode xn in List)
{
System.Xml.XmlElement xe = (System.Xml.XmlElement)xn;
if (xe.GetAttribute("name") == name)
{
System.Xml.XmlNodeList listnode = xe.ChildNodes;
foreach (System.Xml.XmlNode xc in listnode)
{
System.Xml.XmlElement xce = (System.Xml.XmlElement)xc;
string cityname = xce.GetAttribute("name");
listcity.Add(cityname);
}
}
}
return listcity;
}
那arrList[i]的值是什么?
自己可以好好分析一下数据结构。
明明 定义的是 一维的 list
var city_text=arrList[i]["city"];//这里获得的总是undefined
var city_value=arrList[i]["city"];//这里获得的总是undefined
用到这里怎么变2维?
何况数组可使用["city"]?