0

I have two JSON objects one that holds the Buildings and the other that holds the rooms. One fails and one succeeds. They both come in code,value pairs.

Both are attached to drop down menus. The Bldgs shows the result while the rooms fails with the above error.

The bldgs JSON retrieved from the server looks like this

[{
  "code": "Bldgs",
  "value": "A"
}, {
  "code": "Bldgs",
  "value": "J"
}, {
  "code": "Bldgs",
  "value": "I"
}, {
  "code": "Bldgs",
  "value": "H"
}, {
  "code": "Bldgs",
  "value": "G"
}, {
  "code": "Bldgs",
  "value": "F"
}, {
  "code": "Bldgs",
  "value": "E"
}, {
  "code": "Bldgs",
  "value": "D"
}, {
  "code": "Bldgs",
  "value": "C"
}, {
  "code": "Bldgs",
  "value": "B"
}, {
  "code": "Bldgs",
  "value": "K"
}]

Where as the Rooms look like this

[{
  "code": "Rooms",
  "value": "1"
}, {
  "code": "Rooms",
  "value": "7"
}, {
  "code": "Rooms",
  "value": "6"
}, {
  "code": "Rooms",
  "value": "4"
}, {
  "code": "Rooms",
  "value": "3"
}, {
  "code": "Rooms",
  "value": "2"
}, {
  "code": "Rooms",
  "value": "16"
}, {
  "code": "Rooms",
  "value": "15"
}, {
  "code": "Rooms",
  "value": "14"
}, {
  "code": "Rooms",
  "value": "13"
}, {
  "code": "Rooms",
  "value": "12"
}, {
  "code": "Rooms",
  "value": "11"
}, {
  "code": "Rooms",
  "value": "9"
}]

I tried

   var roomList,bldgList= [];
   dropdowns.listdrops({'code':'Rooms'})
    .$promise
    .then(
        function(data) {
            $log.info("Rooms:" + data.length);
             if (typeof data != "undefined") {
                for(var i = 0, len = data.length; i < len; i++) {
                    roomList[i] = data[i].value;    //ERROR HERE        
                };   
             }                      
        }
    );

   dropdowns.listdrops({'code':'Bldgs'})
    .$promise
    .then(
        function(data) {
            $log.info("Blgds:" + data.length);
            if (typeof data != "undefined") {
                for(var i = 0, len = data.length; i < len; i++) {
                    bldgList[i] = data[i].value;    //NO ERROR         
                };                          
            } else {
                $log.info('ERROR: no Drops');
            }
        }, function(error) {
            $log.info('No Drop downs- Server error');
        }   
    );

enter image description here

I even tried bypassing the server service call and doing this

   var test =               [{"code":"Rooms","value":"1"},ode":"Rooms","value":"7"},{"code":"Rooms","value":"6"},{"code":"Rooms","value":"4"},{"code":"Rooms","value":"3"},{"code":"Rooms","value":"2"},{"code":"Rooms","value":"16"},{"code":"Rooms","value":"15"},{"code":"Rooms","value":"14"},{"code":"Rooms","value":"13"},{"code":"Rooms","value":"12"},{"code":"Rooms","value":"11"},{"code":"Rooms","value":"9"}];`
   for(var i = 0, len = test.length; i < len; i++) {
        roomList[i] = test[i].value;    //ERROR        
   }; 
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
devsahem
  • 83
  • 3
  • 15

1 Answers1

0

You need to initialise roomList. var roomList,bldgList= []; should be

var roomList = [],
    bldgList = [];
varun
  • 652
  • 4
  • 5