extjs 新手一枚,想知道 后台给ext传json格式该怎么传?

sdu_hanson 2015-04-10 01:47:23
后台用的是stucts2,
我的前端代码

var chargeElecStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'getChangeElecDevice.action'}),//提交的页面
reader: new Ext.data.JsonReader({ root: "root"}, [
{name: 'deviceID',mapping:'deviceID',type:'string'},
{name: 'deviceNm',mapping:'deviceNm',type:'string'},
{name: 'deviceCode',mapping:'deviceCode',type:'string'}
])
});
chargeElecStore.load();



action中代码

private JSONArray deviceList;

public JSONArray getDeviceList() {
return deviceList;
}

public void setDeviceList(JSONArray deviceList) {
this.deviceList = deviceList;
}

public String execute() throws Exception
{
List<ChargeElecDevice> deviceLst = deviceDao.getChangeDev();

JSONArray jsonArray = JSONArray.fromObject(deviceLst);
this.setDeviceList(jsonArray);
return SUCCESS;
}


stucts.xml

<package name="evcs.action" extends="json-default">
<!--获取充电机-->
<action name="getChangeElecDevice" class="evcs.action.GetElecDeviceAction">
<result name="success" type="json">
<param name="root">deviceList</param>
</result>
<result name="error" type="json">
<param name="root">deviceList</param>
</result>
</action>
</package>



为什么我前台取不到数据呢?
哪个地方写的不对》谢谢了。
...全文
165 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Go 旅城通票 2015-04-12
  • 打赏
  • 举报
回复
var chargeElecStore = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({url:'getChangeElecDevice.action'}),//提交的页面       
    reader: new Ext.data.JsonReader({ root: "root"})
, fields:[///////
        {name: 'deviceID',mapping:'deviceID',type:'string'},
        {name: 'deviceNm',mapping:'deviceNm',type:'string'},
        {name: 'deviceCode',mapping:'deviceCode',type:'string'}
    ]///)
});
什么版本的ext?4+ 应该上面拿上配置store
wxdawxq 2015-04-10
  • 打赏
  • 举报
回复
引用 6 楼 sdu_hanson 的回复:
有知道的么,郁闷了~~~
stucts2在继承json-default后会自动把root描述中对应的对象转换成json串 没用过EXT, 不过看你EXT的代码你试试改成下面这样

         protected Map deviceList;

	public Map getDeviceList() {
		return deviceList;
	}

	public void setDeviceList(Map deviceList) {
		this.deviceList = deviceList;
	}

	public String execute() throws Exception 
	{ 
		List devices = deviceDao.getChangeDev();
		deviceList = new HashMap<String, Object>();
                deviceList.put(”root“, deviceList );
		return SUCCESS;
	}
sdu_hanson 2015-04-10
  • 打赏
  • 举报
回复
有知道的么,郁闷了~~~
sdu_hanson 2015-04-10
  • 打赏
  • 举报
回复
引用 4 楼 wxdawxq 的回复:



	protected List deviceList= new ArrayList();
	public List getDeviceList() {
		return deviceList;
	}

	public void setDeviceList(List deviceList) {
		this.deviceList = deviceList;
	}

	public String execute() throws Exception 
	{ 
		deviceList = deviceDao.getChangeDev();
		
		return SUCCESS;
	}

你是说直接传list格式的? 还是没反应
wxdawxq 2015-04-10
  • 打赏
  • 举报
回复



	protected List deviceList= new ArrayList();
	public List getDeviceList() {
		return deviceList;
	}

	public void setDeviceList(List deviceList) {
		this.deviceList = deviceList;
	}

	public String execute() throws Exception 
	{ 
		deviceList = deviceDao.getChangeDev();
		
		return SUCCESS;
	}

wxdawxq 2015-04-10
  • 打赏
  • 举报
回复



	protected List deviceList= new ArrayList();
	public List getDeviceList() {
		return deviceList;
	}

	public void setDeviceList(List deviceList) {
		this.deviceList = deviceList;
	}

	public String execute() throws Exception 
	{ 
		List deviceLst = deviceDao.getChangeDev();
		
		return SUCCESS;
	}

sdu_hanson 2015-04-10
  • 打赏
  • 举报
回复
顶顶~~~~~~~~~~~~~~~~~
syhxj 2015-04-10
  • 打赏
  • 举报
回复
照着extjs的api来就行,firebug监控一下看看具体的错误

87,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧