ComponentArt控件分析之ComboBox(2)2011-12-30 博客园 Clingingboy一.来看下数据数据解析首先后台先生成一种数据格式,这种格式跟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方法,把每项都呈现出来