ajax 的一种用法

action

package gts.erp.action.ajax;

import gts.erp.action.base.ERPProxyAction;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.oletech.triangle.component.DataBean;
import com.oletech.triangle.component.FormBean;
import com.oletech.triangle.component.RowBean;
import com.oletech.triangle.component.TableBean;
import com.oletech.triangle.utils.TriangleDefinition;

/**
 * 根据交易账户组Id读取交易帐号
 * 
 */
public class GetTradingAccountByGroupIdAction extends ERPProxyAction {

	@Override
	protected ActionForward doExecute(FormBean parameterFB, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

		DataBean returnData = this.getERPServiceDelegation().getTradingService().getTradingAccountByGroupId(parameterFB);
		TableBean accountTableBean = returnData.getTableBean("TN_GENERIC_ACCOUNT");
		JSONArray jsonArray = new JSONArray();
		for (int i = 0; i < accountTableBean.size(); i++) {
			RowBean rowBean = accountTableBean.get(i);
			String primaryId = rowBean.getCellBeanValue(TriangleDefinition.COLUMN_NAME_CN_ID);
			String name = rowBean.getCellBeanValue(TriangleDefinition.COLUMN_NAME_CN_NAME);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("primaryId", primaryId);
			jsonObject.put("name", name);
			jsonArray.add(jsonObject);
		}
		PrintWriter pw = response.getWriter();
		pw.print(jsonArray.toString());
		pw.flush();
		return null;
	}
}
js

$(function(){
	$("#accountGroupId").change(function(){
		$.ajax({
			type : "post",
			url : contentPath + "/ajax/getTradingAccountByGroupId.do",
			data : {
				accountGroupId : $(this).val()
			},
			success : function(data) {
				 $("#accountId").empty();
				 for ( var p in data ){
				     $("#accountId").append("<option value='"+data[p].primaryId+"'>"+data[p].name+"</option>");
				 }
			},
			dataType : "json"
		});
	});

action

package gts.erp.action.ajax;

import gts.erp.action.base.ERPProxyAction;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.oletech.triangle.component.CellBean;
import com.oletech.triangle.component.FormBean;
import com.oletech.triangle.utils.TriangleUIHelper;

/**
 * 
 * 通过工段ID获取部门列表
 * @author ole
 *
 */
public class GetDepartmentListBySectionIdAction extends ERPProxyAction {

	@Override
	protected ActionForward doExecute(FormBean parameterFB, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		FormBean formBean = this.getERPServiceDelegation().getMasterProductionScheduleService().getDepartmentBySection(parameterFB);
		
		JSONArray jsonArray = new JSONArray();
		for (int i = 0; i < formBean.size(); i++) {
			CellBean cellBean = formBean.get(i);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("departmentId", cellBean.getKey());
			jsonObject.put("departmentName", TriangleUIHelper.getMessageResources(request, cellBean.getValue()));
			jsonArray.add(jsonObject);
		}
		PrintWriter pw = response.getWriter();
		pw.print(jsonArray);
		pw.flush();
		return null;
	}

}

js

/**通过工段ID获取部门列表*/
function getDepartmentListBySectionIdFun(){
	var sectionId=$("#sectionId").val();
	var defvalue = $("#departmentId").attr("defvalue");
	$("#departmentId").empty();
	$.ajax({
		type : "post",
		url : contentPath + "/ajax/getDepartmentListBySectionId.do",
		data : {
			sectionId : sectionId
		},
		async : false,
		dataType : "json",
		success : function(data) {
			if (data) {
				var arr=eval(data);
				for(var i = 0; i < arr.length; i++) {
					$("#departmentId").append("<option value = '"+arr[i].departmentId+"'>"+arr[i].departmentName+"</option>");
				}
				if(defvalue){
					$("#departmentId").find("option[value = '"+defvalue+"']").attr("selected","selected");
				}
			}
		}
	});
	showIePHAndIePersons();
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值