コントローラー内に次のロジックがあります。
public function showvlans()
{
$vlans=$this->switches_model->show_known_vlans($this->uri->segment(5), $this->uri->segment(4));
//filter out VLAN 1 if its included in the list.
$key = array_search('1', $vlans);
unset($vlans[$key]);
header ('Content-Type: application/json; charset=UTF-8');
echo json_encode($vlans);
} // end showvlans
何らかの理由で、配列からレコードを除外した後、json データをループするロジックが機能しなくなりました。
json データをループするロジックは次のとおりです。
alert(returnDataFromController.length);
//loop through results
for(i = 0; i < returnDataFromController.length; i++) {
alert(returnDataFromController[i].VlanId);
htmlstring = htmlstring + "<tr><td><a href=>"+returnDataFromController[i].VlanId+"</a></td><td>"+ returnDataFromController[i].Name+"</td></tr>";
}
手がかり:
アラートには「未定義」と表示されます。
また、配列からレコードを削除する前後にデータをダンプしました。json データは次のようになります。
レコードを削除する前に:
[09:36:52.986] [
{VlanId:"1", Name:"VLAN1", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"3", Name:"VLAN3", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"8", Name:"VLAN8", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"16", Name:"VLAN16", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"20", Name:"VLAN20", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"33", Name:"VLAN33", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"64", Name:"VLAN64", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"65", Name:"VLAN65", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"66", Name:"VLAN66", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"80", Name:"VLAN80", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"96", Name:"VLAN96", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"101", Name:"VLAN101", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"128", Name:"VLAN128", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"131", Name:"VLAN131", Status:"Port-based", Voice:"No", Jumbo:"No"},
{VlanId:"417", Name:"VLAN417", Status:"Port-based", Voice:"No", Jumbo:"No"}]
後:
[09:34:41.797] (
{1:{VlanId:"3", Name:"VLAN3", Status:"Port-based", Voice:"No", Jumbo:"No"},
2:{VlanId:"8", Name:"VLAN8", Status:"Port-based", Voice:"No", Jumbo:"No"},
3:{VlanId:"16", Name:"VLAN16", Status:"Port-based", Voice:"No", Jumbo:"No"},
4:{VlanId:"20", Name:"VLAN20", Status:"Port-based", Voice:"No", Jumbo:"No"},
5:{VlanId:"33", Name:"VLAN33", Status:"Port-based", Voice:"No", Jumbo:"No"},
6:{VlanId:"64", Name:"VLAN64", Status:"Port-based", Voice:"No", Jumbo:"No"},
7:{VlanId:"65", Name:"VLAN65", Status:"Port-based", Voice:"No", Jumbo:"No"},
8:{VlanId:"66", Name:"VLAN66", Status:"Port-based", Voice:"No", Jumbo:"No"},
9:{VlanId:"80", Name:"VLAN80", Status:"Port-based", Voice:"No", Jumbo:"No"},
10:{VlanId:"96", Name:"VLAN96", Status:"Port-based", Voice:"No", Jumbo:"No"},
11:{VlanId:"101", Name:"VLAN101", Status:"Port-based", Voice:"No", Jumbo:"No"},
12:{VlanId:"128", Name:"VLAN128", Status:"Port-based", Voice:"No", Jumbo:"No"},
13:{VlanId:"131", Name:"VLAN131", Status:"Port-based", Voice:"No", Jumbo:"No"},
14:{VlanId:"417", Name:"VLAN417", Status:"Port-based", Voice:"No", Jumbo:"No"}})
ご覧のとおり、見た目が少し異なります。unset を使用する前は開口部がありますが[
、使用後は(
. i
変数が代わりに開始するようにループ制御を変更しようとしまし1
た...しかし、それも機能しませんでした。
たとえば、次のことを試しました。
for(i = 1; i < returnDataFromController.length; i++) {
それ以外の
for(i = 0; i < returnDataFromController.length; i++) {