Chydar 2012-09-20
ext ajax json与struts实例
ext的javascript代码:
//提交修改 function submitUpdate(grid,colIndex,rowIndex,id){ //后台semanticsBean var sentence = Ext.getCmp('updateSentence').getValue(); var template = Ext.getCmp('updateTemplatesql').getValue(); var tableids = Ext.getCmp('updateTableids').getValue(); var jsonBean = { 'bean.id' : id, 'bean.sentence' : sentence, 'bean.template' : template, 'bean.tableids' : tableids } var bean = {id:id,sentence:sentence,template:template,tableids:tableids}; Ext.Ajax.request({ url:'./modifySemantics', params:jsonBean, success:function(r,o){ reRenderTable(grid,colIndex,rowIndex,bean); }, failure:function(){ Ext.Msg.alert("更新有误","更新有误,当前数据过旧,请刷新重试"); } }); }
struts配置文件:
<!-- 更新语义库记录 --> <action name="modifySemantics" class="com.xxxx.vbap.nl.action.NLManageAction" method="updateSemanticsList"> </action>
strut java代码:
类中属性
// 前台传输实体bean private SemanticsSqlTemp bean = new SemanticsSqlTemp();
public String updateSemanticsList(){ try{ if(this.bean == null || this.bean.getId() == 0){ logger.error("更新语义库sql模板报错,传输数据缺少ID"); return Action.NONE; } ArrayList<Object> keyvalueList = new ArrayList<Object>(); ArrayList<Class<?>> classtypeList = new ArrayList<Class<?>>(); bean.setUpdateData(keyvalueList, classtypeList); String sql = "update sql_template_set set sentence = ?,templatesql = ?,tableids = ? where id = ?"; NLSqlAnalysis.updateByID(sql, bean, keyvalueList, classtypeList); return Action.NONE; }catch (Exception e) { logger.error("更新语义库sql模板报错",e); return Action.ERROR; } }
这样就可以让struts接收json对象
再附上一个解析传回的json对象代码
function showSemanticsList(type,renderDivID) { //var showradio = Ext.getCmp("showRadioGroup"); //var showtype = getRadioInputValue(showradio);//获取数据标志 Ext.Ajax.request({ url:'./showSemantics', params:{ showType:type }, success : function(r,o){ var re = Ext.decode(r.responseText); if(re.length>0) showSemanticsData(type,re,renderDivID);//TODO: else{ document.getElementById(renderDivID).innerHTML = ""; Ext.Msg.alert("无所选数据"); } }, failure : function(){ Ext.Msg.alert("语义库查询有误","语义库查询有误"); } }); }
在js中解析json对象:
function showItem(grid,colIndex,rowIndex){ var id = rowIndex.data.id; Ext.Ajax.request({ url:'./getSemantics', params:{id:id}, success:function(r,o){ var re = Ext.decode(r.responseText); showItemEditPage(2,grid,colIndex,rowIndex,re); }, failure:function(){Ext.Msg.alert("语义查询有误","语义查询有误");} }); }
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
本文实例讲述了php+ ajax 实现的写入数据库操作。分享给大家供大家参考,具体如下:。<input class="tel" type="text" placeholder="请输入您的手机号码&q