我正在尝试根据 url 中的值过滤 json 数组并获取属性vernacularName。在 F12 调试中,我可以输入record[0].vernacularName;它,它给了我正确的变量,但下面的代码仍然失败。
document.getElementById("demo").innerHTML = datasetID;有效但document.getElementById("demo").innerHTML = vernacularName;无效。
最终我想添加 vernauralName 作为会话变量
<body>
<div class="">
<h3>testing data</h3>
<p id="demo" class = 'pl-5'></p>
</div>
<script type="text/javascript">
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const species = urlParams.get('species')
const bone = urlParams.get('bone')
const datasetID = urlParams.get('datasetID')
var data;
$.getJSON("json/data.json", function(json){
data = json;
});
record = data.filter(r => r.datasetID == datasetID);
var vernacularName = record[0].vernacularName;
// const vernacularName2 = record.vernacularName;
$_SESSION["v"] = vernacularName;
</script>
<script>
document.getElementById("demo").innerHTML = vernacularName;
</script>
慕雪6442864
相关分类