2023年4月10日 星期一

V80204B -將前端 Array/table/Object 欄位值,傳送至後端處理 -JSON – 將目前 checkboxgroup欄位值(Array),傳送至後端,並處理

 目的: V80204B – 將目前 checkboxgroup欄位值(Array),傳送至後端,並處理

處理說明: 1>若非基本型態(string/int/)的欄位值(Array/table/Object),要傳至後端, 
                       均需先轉成 JSON string型態 ,才可當成np的參數值,傳送至後端
                        *.js                         
                        var Tmp_JSONStr = JSON.stringify(Ext.getCmp('chkboxgrp2').getValue()["rb"]);
                        np["ASN_ARY_JSONStr"]=Tmp_JSONStr;

                  2> 後端接收時,必需先將 JSON string 型態, 再還回原型態(Array/table/Object)
                        *.cs
                        string Tmp_ASN_ARY_JSONStr = nvc["ASN_ARY_JSONStr"];  
                        JArray Tmp_ASN_ARY =      
                     (JArray)JsonConvert.DeserializeObject(Tmp_ASN_ARY_JSONStr, (typeof(JArray)));  


1>*.js

var selectedValues = Ext.getCmp('chkboxgrp2').items;
console.log(selectedValues);
var Tmp_ASNAry = []; //var Tmp_Obj={};
//chkboxgrp2 均設為 true
for (var i = 0; i < selectedValues.length; i++) {
    selectedValues.items[i].setValue(true);
};

var np = {};
//取得 chkboxgrp2 的勾選欄位值
//將 Array 轉成 JSON字串, 以便傳至後端
    var Tmp_JSONStr = JSON.stringify(Ext.getCmp('chkboxgrp2').getValue()["rb"]);
    np["ASN_ARY_JSONStr"]=Tmp_JSONStr;
    console.log("np['ASN_ARY_JSONStr']: ", np["ASN_ARY_JSONStr"]);

2>*.cs    
  string Tmp_ASN_ARY_JSONStr = nvc["ASN_ARY_JSONStr"]; 
  JArray Tmp_ASN_ARY = (JArray)JsonConvert.DeserializeObject(Tmp_ASN_ARY_JSONStr, (typeof(JArray)));
 string Tmp_ASN_ARY_STR = string.Join(",", Tmp_ASN_ARY);
// "A012,B025" -->  'A012','B025'
 Tmp_ASN_ARY_STR = myfunc.AddQuoteStr(Tmp_ASN_ARY_STR); 








PS:
       1>將checkboxgroup2 的項目均設為 勾選(checked)
                 {
                    xtype: 'checkboxgroup',
                    id: 'chkboxgrp1',            // columns: 3,
                    columns: [.35, .35, .35],
                    items: [
                               { boxLabel: 'Item 1', name: 'rb', inputValue: '1' },
                               { boxLabel: 'Item 2', name: 'rb', inputValue: '2' },
                               { boxLabel: 'Item 3', name: 'rb', inputValue: '3' },
                             ]
                  },



}, //end of 待挑選機號

                  2>將checkboxgroup2的項目傳送至後端處理                       



沒有留言:

張貼留言