[英]How to send data from one website to another website in React js?
[英]How to send JSON array data from one JS function to Another?
我正在從另一個調用 JS 函數並發送 JSON 數組數據。 在將數據發送到第二個函數時,我得到的值為 undefined/null。 如何將 JSON 數組數據從一個 JS 函數發送到另一個?
功能:1
$(function createJsonArray() {
var categories = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
];
var confidence = [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4];
var jsonArray = {
issueData: []
};
jsonArray.issueData.push({
"categories": categories,
"confidence": confidence
});
//alert('categories: ' + jsonArray.issueData[0].categories);
// calling function-2
createGraph(JSON.stringify(jsonArray));
});
功能:2
$(function createGraph(graphData) {
var jsonArray = $.parseJSON(graphData);
alert('jsonArray: ' + jsonArray);
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: jsonArray.issueData[0].categories,
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Rainfall (mm)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Tokyo',
data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
});
JSfiddle鏈接
檢查此更新小提琴
您需要調用createJSONArray()
方法並擺脫$(function functionName)
的 jquery 調用,而只需定義一個簡單的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.