关于Combo Box的分页(级联菜单)

JS代码:
var neNameStore = new Ext.data.JsonStore({
				fields:['displayField','valueField'],
				url:'comboBox.shtml?method=getNeInfos',
				root:'root', 
				totalProperty:'totlalNum',
				autoLoad:false
			}); 


{
					xtype:'combo',
					width : 100,
					allowBlank : false,
					blankText : '选择设备类型',
					hiddenName : 'neType',
					name : 'neTypeValue',
					id : 'neTypeValue',
					store : neTypeStore,
					triggerAction: 'all',
					editable : false,
					displayField:'displayField',
					valueField : 'valueField',
					emptyText :'设备类型',
					mode: 'local',
					value:'-1',
					listeners:{
						select: function(combo, record, index){
							var neTypeValue = record.data.valueField;
							var neNameCombo = Ext.getCmp('neIdValue');
							neNameCombo.clearValue();
							neNameStore.removeAll();
							if(neTypeValue != '-1'){	
								neNameStore.baseParams['neType'] = neTypeValue;
								neNameStore.reload({params:{start:0,limit:128}});
								
								neNameCombo.enable();
							}
							else{
								neNameCombo.disable();
							}
						}
					}
				},
				'设备名称: ',
				{
					xtype:'combo',
					width : 150,
					allowBlank : false,
					blankText : '选择设备',
					hiddenName : 'neId',
					name : 'neIdValue',
					id : 'neIdValue',
					store : neNameStore,
					triggerAction: 'all',
					editable : true,
					minChars:128,
					displayField:'displayField',
					valueField : 'valueField',
					minListWidth:235,  
					emptyText :'设备名称',
					disabled:true,
					mode: 'remote',
					pageSize:128
				}

Java代码:
public ActionForward getNeInfos(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception
	{
		logger.info("ComboBoxAction.class => getNeInfos");
		
		String start = request.getParameter("start");
		String limit = request.getParameter("limit");
		
		int index = Integer.parseInt(start);
		int max = Integer.parseInt(limit) + index;
		
		int neType = Integer.parseInt(request.getParameter("neType"));
		
		Map<Integer, String> map = WebNeInfos.getNeInfoMapByNeType(neType);
		Object[] key = map.keySet().toArray();   
		Arrays.sort(key);
		
		int size = map.size();
		if(max > size)
		{
			max = size;
		}
		
		response.setContentType("text/json;charset=UTF-8");
		StringBuffer sb = new StringBuffer();
		sb.append("{totlalNum:'" + size + "',");
		sb.append("root:[");
		for(int i=index; i<max; i++)
		{
			sb.append("{displayField:'" + map.get(key[i]) + "',valueField:'" + key[i] + "'}");
			
			if(i<max-1)
			{
				sb.append(",");
			}
		}
		sb.append("]}");
		
		log.info("json => " + sb.toString());
		response.getWriter().write(sb.toString());
		
		return null;
	}

你可能感兴趣的:(json,ext)