问题描述:
1.Combobox组件远程加载失败,load之后没有任何选项,貌似是proxy获取不了Action传来的数据。
2.使用HttpProxy构造方法创建一个代理对象时,其构造方法需要一个Connection类型的参数,为什么我在按照Connection的配置项配置完成之后,页面加载前后listeners中的两个事件触发不了?
代码如下:
前台ExtJs代码:
- JScript code
Ext.onReady(function(){ var httpProxy = new Ext.data.HttpProxy({ url:'httpComboboxAction.action', listeners:{ requestcomplete:function(conn,response,options){ alert(response.responseText()); }, beforerequest:function(conn,options){ alert(111); } } }); var httpRecord = new Ext.data.Record.create([ {name:'id',type:'int',mapping:'id'}, {name:'cname',type:'string',mapping:'cname'} ]); var jsonReader = new Ext.data.JsonReader({},httpRecord); var httpStore = new Ext.data.Store({ proxy:httpProxy, reader:jsonReader }); var httpCombobox = new Ext.form.ComboBox({ store:httpStore, mode:'remote', renderTo:'httpCombobox', valueField:'id', displayField:'cname', triggerAction:'all' }); });
后台Action代码:
- Java code
package org.action.extjstest; import java.io.IOException; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class ComboboxAction extends ActionSupport{ public String httpDataToCombobox() throws IOException{ System.out.println("11111111"); HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); // response.setCharacterEncoding("utf-8"); response.getWriter().write( "[{id:1,cname:北京},{id:2,cname:青岛},{id:3,cname:济南}]" ); return null; } }
------解决方案--------------------
response.getWriter().write(
"[{id:1,cname:北京},{id:2,cname:青岛},{id:3,cname:济南}]"
); 这个必须转化成json字符串的形式输出的,你的json格式也不对