javascript - Angular Array instead of object -


i have following html in view. on ng-click on button when log out value, value object numbers keys in it, instead of array. know going wrong?

what gets logged object key of 0, accessed like: objectname.0

              <div class="equipitems" ng-repeat="(key,value) in day.equipment track $index">                    <label class="item item-input item-select">                     <div class="input-label">                         {{key}}                     </div>                     <select ng-model="value[$index].itemname" ng-options="item item item in equipment.{{key}}">                         <option value="">select option</option>                     </select>                     </label>                     <label class="item item-input">                         <input type="number" ng-model="value[$index].value" placeholder="amount/value">                     </label>                      <button class="button button-balanced button-outline button-block" ng-click="additem(value)">                       add {{key}}                     </button>                </div> 

here structure of day object.

{                 staff : [                     {                         name : '',                         designation : '',                         timein : '',                         timeout : ''                     }                 ],                 vehicles : [                     {                         type : '',                         distance : ''                     }                 ],                 equipment : {                     staff : [                         {                             itemname : '',                             value : ''                         }                     ],                     equipment : [                         {                             itemname : '',                             value : ''                         }                     ],                     vehicles : [                         {                             itemname : '',                             value : ''                         }                     ],                     absorbents : [                         {                             itemname : '',                             value : ''                         }                     ],                     ppe : [                         {                             itemname : '',                             value : ''                         }                     ]                  },                 comment :  [                     {                         time : '',                         comment : ''                     }                 ],                 photos : [                     {                         src : '',                         comment : ''                     }                 ]             } 

just create demo here: jsfiddle

in functtion additem, put this:

 $scope.additem = function(value){     console.log(value);  // [object]     console.log(typeof(value)); //object     console.log(object.prototype.tostring.apply(value)); //[object array]  still array     console.log(value[0]); // object }; 

value still array. element inside array object. like:

{     itemname : '',     value : '' } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -