jquery窗口間json數組串處理

定義一個數組對象,並按特定格式分割成數組 html

var existsItemArr = new Array();
var existsItems = "${existsItems}";
if(null !=  existsItems && "" != existsItems){
 existsItemArr = existsItems.split(",");
} node

 刪除數組中的一個元素,首先判斷在數組中的位置(是否存在),再進行刪除。 json

existsItemArr.splice($.inArray(checkItemId, existsItemArr),1); 數組

判斷數組是否爲空,並用默認的","號進行組成字符串 this

 if(!$.isEmptyObject(existsItemArr)){//判斷對象是否爲空
  params += "&existsItems="existsItemArr.toString();//等同於join()
 } spa

對話框進行帶參傳值,並返回json格式的數組結果 orm

var sURL = "*.do"+params;
 var vArguments = new Object();//對話框經過window.dialogArguments來取得傳遞進來的參數。 vArguments.win=window;//把當前窗口的引用當參數傳進去
 var sFeatures = "dialogHeight:350px;dialogWidth:750px;center:yes;resizable:yes;status:no;location:no;menubar:no;titlebar:no;";
 
 var vReturn = window.showModalDialog(sURL,vArguments,sFeatures);
 if(undefined !=vReturn && $.isArray(vReturn)){//並判斷是不是數組
  dynAddRow(vReturn);
 } htm

 function dynAddRow(rowdataArray){

 
 $.each(rowdataArray, function(key, val) {
  var rowdata = jQuery.parseJSON(val);

  $(":hidden[name='OeModelItems.nodeId']",$("#**")).val(nodeId);//可見性選擇器和 容器過濾器

  //對處理過的回車換行符進行處理
  var surveyContent = rowdata.surveyContent.replace(/<br\>/gm,"\n");

  $(":hidden[name='OeModelItems.checkItemId']",tmp).val(rowdata.checkItemId);//json對象屬性取值

    //添加選擇元素以前,並轉換成html格式信息
  $("#dynRow").before("<tr align='center'>"+tmp.html()+"</tr>");

  existsItemArr.push(rowdata.checkItemId);//添加到數組
   對象

  //var addRow=$("#sampleItem");//獲取元素,並克隆副本
  //var tmp = addRow.clone();
  //綁定特定事件,須要先刪除所綁定的事件
  //$(".remove").unbind("click");
  //$(".remove").bind("click",removeTR);
 });
事件

//模態對話框傳值 
function submitForm(){
 var returnArray = []; //去選中的ID
 $("input[name='selChc']").each(function(){
  if($(this).attr("checked")){//對象的某一個屬性值
    var $tr = $(this).parent("td").parent("tr");//元素的父節點
    var $tds = $tr.find("td");//查詢當前元素下的全部子元素信息

    var checkItemId = $(":hidden[name='oeInspectionItems.checkItemId']",$tds.eq(1)).val();//獲取值
    //針對特定屬性 選擇用text() 或 val()方法
    var surveyContent = $tds.eq(2).text();
    surveyContent = surveyContent.replace(/\n/gm,"<br\>");//爲處理json的轉換時的特定字符
     //組成json格式的字符串,屬性名和屬性值必須用引號包裹。

    var rowdataStr = '{"checkItemId":"'+checkItemId
    +'","surveyContentCn":"'+surveyContentCn

    +'"}';
    returnArray.push(rowdataStr);//添加對象

 }); 

var size = returnArray.length;
if(size == 0){//數據校驗
alert("Don't selected rowData!");
return false;
}

window.returnValue = returnArray;//爲window對象,傳遞返回值 window.close(); }

相關文章
相關標籤/搜索