Home > Web Front-end > JS Tutorial > Detailed explanation of data interception issues in JavaScript

Detailed explanation of data interception issues in JavaScript

小云云
Release: 2018-05-22 10:45:09
Original
2302 people have browsed it

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())
Copy after login

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(&#39;.selected&#39;).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)
Copy after login

The output is:


②With field name

 //1. 获取table表中所有的打钩记录
                var formData = $("#tbMain table").DataTable().rows(&#39;.selected&#39;).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))
Copy after login

The output is:


2. Data display

<p class="cnt"></p>
<script>
	var data=[{name:&#39;小林&#39;,score:"100分"},{name:&#39;小高&#39;,score:"99分"}];
	$(function() {
		creatp(data);
	});
	function creatp(data){
		var text=&#39;&#39;;
		for(var i=0;i<data.length;i++){
			text +=data[i].name+"得" +data[i].score+"数,";
		}
		text=text.slice(0,text.length-1);//删除最后的逗号
		var html=&#39;<p>学生中有:&#39;+ text +&#39;获得奖学金!</p>&#39;;
		$(&#39;.cnt&#39;).append(html);
	}
</script>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template