一.來看下數據數據解析
首先後台先生成一種數據格式,這種格式跟JSON差不多(不知道為什麼不用JSON),查看HTML源代碼
ComboBox2.Data = [[['Text','a'],['Value','b']],[['Text','b'],['Value','c']],[['Text','c'],['Enabled',0],['Value','b']],[['CssClass','comboItemHover'],['Text','d'],['Value','c'],['Id','ComboBoxItem1']],[['Text','a'],['Value','b']],[['Text','b'],['Value','c']],[['Text','c'],['Enabled',0],['Value','b']],[['CssClass','comboItemHover'],['Text','d'],['Value','c'],['Id','ComboBoxItem2']],[['Text','a'],['Value','b']],[['Text','b'],['Value','c']],[['Text','c'],['Enabled',0],['Value','b']],[['CssClass','comboItemHover'],['Text','d'],['Value','c'],['Id','ComboBoxItem3']],[['Text','a'],['Value','b']],[['Text','b'],['Value','c']],[['Text','c'],['Enabled',0],['Value','b']],[['CssClass','comboItemHover'],['Text','d'],['Value','c'],['Id','hello']]];
2.需要定義一個ComboBoxItem對象(自然要定義數據集合類型了),其中js也要定義,數據結構采用HashTable,查找速度快.其中定義了一個JavaScriptArray用來轉換數據
private string BuildStorage()
{
JavaScriptArray arNodeList = new JavaScriptArray();
foreach (ComboBoxItem oItem in this.Items)
{
ProcessItem(oItem, arNodeList);
}
string strList=arNodeList.ToString();
return strList;
}
private void ProcessItem(ComboBoxItem oItem, ArrayList arNodeList)
{
ArrayList itemProperties = new ArrayList();
foreach (string propertyName in oItem.Properties.Keys)
{
switch (propertyName.ToLower())
{
// bools
case "enabled": itemProperties.Add(new object[] { "Enabled", oItem.Enabled }); break;
// normal string handling
default:
itemProperties.Add(new object[] { propertyName, oItem.Properties[propertyName] });
break;
}
}
arNodeList.Add(itemProperties);
}
3.前台處理數據
數據得到以後就要處理
前段的ComboBox(Initialize)初始化時會調用Render方法,Render方法會調用RenderDropDown方法,RenderDropDown方法調用RenderItem方法,把每項都呈現出來