html:
<div class="odf_details" id="con_details_nttn_odf_details">
<span class="hidden_id">con_details_nttn_odf_details</span>
<span class="msg"></span>
<table border="1" cellspacing=0 cellpadding=2 class="dtable" align="center" width="100%">
<tr>
<th>NTTN ODF:</th>
<th>Tray</th>
<th>Port</th>
<th>Circuit Type</th>
</tr>
<tr class="odf_data_tr">
<td class="odf_name_td">
<input class="odf_name" type="text" name="nttn_odf_name" disabled="disabled" />
</td>
<td class="odf_tray_td">
<select class="odf_tray" name="con_details_nttn_odf_tray">
<option value="">Please Select</option>
<option value="a" <?php if ($services['con_details_nttn_odf_tray'] == 'a') echo 'selected'; ?> >A</option>
<option value="b" <?php if ($services['con_details_nttn_odf_tray'] == 'b') echo 'selected'; ?> >B</option>
<option value="c" <?php if ($services['con_details_nttn_odf_tray'] == 'c') echo 'selected'; ?> >C</option>
<option value="c" <?php if ($services['con_details_nttn_odf_tray'] == 'd') echo 'selected'; ?> >D</option>
</select>
</td>
<td class="odf_ports_td" align="center">
<span class="hidden_info"><?php echo $services['con_details_nttn_odf_port'] ?></span>
1<input type="checkbox" name="con_details_nttn_odf_port" value="1" />
2<input type="checkbox" name="con_details_nttn_odf_port" value="2" />
3<input type="checkbox" name="con_details_nttn_odf_port" value="3" />
4<input type="checkbox" name="con_details_nttn_odf_port" value="4" />
5<input type="checkbox" name="con_details_nttn_odf_port" value="5" />
6<input type="checkbox" name="con_details_nttn_odf_port" value="6" />
7<input type="checkbox" name="con_details_nttn_odf_port" value="7" />
8<input type="checkbox" name="con_details_nttn_odf_port" value="8" />
9<input type="checkbox" name="con_details_nttn_odf_port" value="9" />
10<input type="checkbox" name="con_details_nttn_odf_port" value="10" />
</td>
<td>
<select name="con_details_nttn_odf_circuit_type">
<option value="">Please Select</option>
<option value="primary" <?php if ($services['con_details_nttn_odf_circuit_type'] == 'primary') echo 'selected'; ?> >Primary</option>
<option value="secondary" <?php if ($services['con_details_nttn_odf_circuit_type'] == 'secondary') echo 'selected'; ?> >Secondary</option>
</select>
</td>
</tr>
</table>
</div>
後で必要な JavaScript ファイルを追加し、そこでオブジェクトを宣言しました。
var odf_data = {
num_ports_in_each_tray: 10,
added_odfs_total: 0,
must_update: false,
uniq_ports_per_tray_collection: build_uniq_ports_collection()
};
function build_uniq_ports_collection() {
var odf_ports = new Array(4);
odf_ports['a'] = new Array(odf_data.num_ports_in_each_tray);
odf_ports['b'] = new Array(odf_data.num_ports_in_each_tray);
odf_ports['c'] = new Array(odf_data.num_ports_in_each_tray);
odf_ports['b'] = new Array(odf_data.num_ports_in_each_tray);
odf_names_array = new Array(); //odf names should be unique
var error = '';
$('div.odf_details').each(function() {
//now we are inside each odf's immediate parent div
var tray = $(this).find('td.odf_tray_td select.odf_tray :selected').val();
var odf_name = $(this).find('td.odf_name_td input.odf_name').val();
$(this).find('td.odf_ports_td input:checked').each(function() {
var port = $(this).val();
if (!error && odf_ports[tray][port] === undefined) {
odf_ports[tray][port] = odf_name;
} else {
$(this).prop('checked', false);
}
});
if (odf_data.must_update) {
alert('there were some errors in port, you must update and save');
}
});
return odf_ports;
}
しかし、まさにこの行でfirebugコンソールにエラーが表示されます:
odf_ports['a'] = new Array(odf_data.num_ports_in_each_tray);
TypeError: odf_data is undefined
私はただ考えています、なぜですか?オブジェクトを正しく定義しましたか? しかし、なぜ未定義として報告されるのですか?? 迅速なヘルプをいただければ幸いです