頁面JShtml
- function ajaxClient(_id,_type){
- $.ajax({
- type: "POST",
- url:"${pageContext.request.contextPath}/projectManage/project!queryClientSort.action",
- dataType: "json",
- data: "ids=" + _id + "&type=" + _type,
- success: function(data){
- var json = eval(data); //eval("(" + data + ")");
- if(_type==1){
- $("#clientBasic").html('<option value="-1">請選擇客戶名稱</option>');
- // $("#contract").html('<option value="-1"> 請選擇合同編號</option>');
- }
- else if(_type==2){
- $("#clientBasic").html('<option value="-1">請選擇客戶名稱</option>');
- //$("#contract").html('<option value="-1"> 請選擇合同編號</option>');
- }else if(_type=3){
- $("#contract").html('<option value="-1"> 請選擇合同編號</option>');
- }
- $.each(json, function(idx, item) {
- // var user = item.UserName;
- // var pass = item.PWD;
- if(_type==1){
- //$("#clientSort").append('<option value="' + item.stId + '"> ' + item.name + '</option>');
- }
- else if(_type==2){
- $("#clientBasic").append('<option value="' + item.clientId + '"> ' + item.clientName + '</option>');
- }else if(_type==3){
- $("#contract").append('<option value="' + item.contractId + '"> ' + item.contractNumber + '</option>');
- }
- });
- }
- });
- }
- //頁面元素的驗證
- $(function(){
- /**
- *Ajax獲取數據 start
- */
- $('#clientSort').change(function() {
- if($('#clientSort').val()>0){
- ajaxClient($('#clientSort').val(),2);
- }else{
- $('#clientBasic :not(option:eq(0))').remove();
- }
- });
- $('#clientBasic').change(function() {
- if($('#clientBasic').val()>0){
- ajaxClient($('#clientBasic').val(),3);
- }else{
- $('#contract :not(option:eq(0))').remove();
- }
- });
- $('#list_table tr:even').addClass('even_list');
- /**
- *Ajax獲取數據 stop
- */
- })
ProjectActionajax
- /**
- * ajax得到數據
- *
- * @return
- * @throws Exception
- */
- public String queryClientSort() throws Exception {
- JsonConfig cfg = new JsonConfig();
- cfg.setJsonPropertyFilter(new PropertyFilter() {
- //取消這些屬性封裝成json
- public boolean apply(Object source, String name, Object value) {
- if (name.equals("staticType") ||name.equals("agencyCompany") || name.equals("contracts")
- || name.equals("users") || name.equals("projects") || name.equals("clientBasic")) {
- return true;
- } else {
- return false;
- }
- }
- });
- JSONArray jsonArray = null;
- if (type != null && "1".equals(type)) {
- clientSortList=clientSortSTService.queryAll();
- if(clientSortList != null)
- {
- jsonArray = JSONArray.fromObject(clientSortList, cfg);
- }
- } else if (type != null && "2".equals(type)) {
- //查詢客戶分類ID下的客戶集合
- clientBasicList=clientBasicService.queryClientBasic_ClientSortId(Integer.valueOf(ids));
- System.out.println("客戶集合大小:"+clientBasicList.size());
- if(clientBasicList != null)
- {
- jsonArray = JSONArray.fromObject(clientBasicList, cfg);
- }
- }else if(type!=null && "3".equals(type)){
- //查詢客戶下的合同信息集合
- contractList=clientBasicService.queryContract(Integer.valueOf(ids));
- if(contractList !=null){
- jsonArray = JSONArray.fromObject(contractList, cfg);
- }
- }
- // JSONArray json =
- // JSONArray.fromObject(topicService.getClientBasic(1));
- if (jsonArray != null) {
- PrintWriter pt = null;
- try {
- ActionContext ctx = ActionContext.getContext();
- HttpServletResponse response = (HttpServletResponse) ctx
- .get(ServletActionContext.HTTP_RESPONSE);
- response.setContentType("text/html; charset=UTF-8");
- pt = response.getWriter();
- pt.write(jsonArray.toString());
- pt.flush();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return null;
- }