bootstrap-table的行數據使用array和json的區別

//bootstrap-table中的data參數傳的只能是數組數據,json數據不行,通過url參數傳數據時,可以傳json數據,但此時還需要配置參數
responseHandler: function (res) {
return res.rows;

}

返回json數據中的行數據數組,所以最終使用的還是json中的數組。可通過

Object.prototype.toString.call(newData).toLowerCase()

判斷數據是數組還是json對象,數組添加新數據不知道數組索引的情況下可以使用push()函數,


if(devType == "信號機"&&unit=="A單位") {
			var newData = [];
			for(var p in wcssdata) {
				console.log(wcssdata[p]);
				if(wcssdata[p].type == devType&& wcssdata[p].maintain_unit==unit) {
					newData.push(wcssdata[p]); //給數組添加新對象數據
					//newData[0]=wcssdata[p];
				}
			}
			console.log(newData)
			console.log(Object.prototype.toString.call(newData).toLowerCase())//[object array]
			console.log(Object.prototype.toString.call(wcssdata).toLowerCase())
			$("#table").bootstrapTable('refreshOptions', {
				data: newData,
			});
		}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章