Home > Article > Web Front-end > Detailed explanation of data interception issues in JavaScript
This article mainly shares with you the detailed explanation of data interception issues in JavaScript, hoping to help everyone.
1. Obtain from the array
1. Get the value of value
var revokeModel = $("#modalMsgRevoke form").serializeArray();
console.log('cxyy00:'+revokeModel[0].value)
2. Get 1 field from a set of data arrays
var formData = $("#tbMain table").DataTable().rows('.selected').data(); var arr=new Array(); for(var i=0;i<formData.length;i++){ arr.push(formData[i].bgxmid); } console.log(arr.toString())
or
or when it is a string
3. Get 2 fields from a data array to form a two-dimensional array (getting multiple fields is also possible)
##①Without field
var formData = $("#tbMain table").DataTable().rows('.selected').data(); //2.截取出 诊疗项目ID(zlxmid) 报告项目ID(bgxmid) 仪器字典编号(yqzdbh) var arr=new Array();//这是定义数组来存储 需要的字段 for(var i=0;i<formData.length;i++){ arr[i] = new Array();//定义外面那个arr下面的二维数组 arr[i].push(formData[i].bgxmid); arr[i].push(formData[i].yqzdbh); arr[i].push(formData[i].zlxmid); } var zlxmmc_id=Number(staData.id);//转出整数 //2.2把输入的诊疗项目名称 赋值给 新的数组 for(var i=0;i<arr.length;i++){ arr[i][2]=zlxmmc_id; } console.log(arr)The output is:
//1. 获取table表中所有的打钩记录 var formData = $("#tbMain table").DataTable().rows('.selected').data(); //2.截取出 诊疗项目ID(zlxmid) 报告项目ID(bgxmid) 仪器字典编号(yqzdbh) var arr=new Array();//这是定义数组来存储 需要的字段 var zlxmmc_id=Number(staData.id);//转出整数 for(var i=0;i<formData.length;i++){ var object = new Object(); object.bgxmid = formData[i].bgxmid; object.yqzdbh = formData[i].yqzdbh; object.zlxmid = zlxmmc_id; arr.push(object); } console.log(arr) //转成json格式 console.log(JSON.stringify(arr))The output is:
<p class="cnt"></p> <script> var data=[{name:'小林',score:"100分"},{name:'小高',score:"99分"}]; $(function() { creatp(data); }); function creatp(data){ var text=''; for(var i=0;i<data.length;i++){ text +=data[i].name+"得" +data[i].score+"数,"; } text=text.slice(0,text.length-1);//删除最后的逗号 var html='<p>学生中有:'+ text +'获得奖学金!</p>'; $('.cnt').append(html); } </script>
The above is the detailed content of Detailed explanation of data interception issues in JavaScript. For more information, please follow other related articles on the PHP Chinese website!