これは私が支援を求めるのは初めてのことです (まだ少し初心者のコーダーです)。
何千ものアイテムを持つ JSON ファイルを作成しました。そのファイルからさまざまなページにドロップダウンを動的に入力し、後で以前の選択に基づいてドロップダウンを動的に入力できるようにしたいと考えています。私はこれを徹底的に調査しましたが、私が見つけたほとんどのチュートリアルと質問は、この特定の方法では機能しないようです. 基本的に、ページをロードすると、アイテムが表示されません。つまり、ドロップダウンは空です。コンソールにはエラーが 1 つだけ表示されます。これは、見つけたすべての情報によると、CDN が読み込まれていないことを示しています。だから、ここにあります:
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<select id="mainhand"></select>
<br>
<select id="offhand"></select>
<script type="text/javascript">
$(document).ready(function() {
//request the JSON data and parse into the select element
$.getJSON('http://nodtools.net/stats.json', function(obj) {
//iterate over the data and append a select option
$.each(data.item, function(key, value) {
// set the value of option to each item in the list as you iterate through
var option = $('<option><option/>').val(value.name).text(value.name);
// almost any of them can be added to the main hand
if (value.type == 'slash' || value.type == 'crush' || value.type == 'pierce' || value.type == 'whip' || value.type == 'staff') {
$('#mainhand').append(option);
};
// only shields and 1h weapons can be in off hand
if (value.hands == 1 || value.type == 'shield') {
$('#offhand').append(option);
// continue on for all types: bow, arrow, quiver, etc.
});
});
});
});
</script>
</body>
</html>
明らかに何かが欠けていると強く感じています...誰かがそれを指摘できれば、私はそれを大いに感謝します!