0

I'm trying to display an array of properties in my view from Javascript but it's not displaying appropriately. It looks like this:

    vm.statesList: [ObjectStateCode: "AL"StateId: 1 StateName: "Alabama"_backingStore: ObjectStateCode: "AL"StateId: 1StateName: "Alabama"__proto__: ObjectentityAspect: ctor__proto__: Object,]

But when i display it like this:

     <select data-ng-model="cdModel.documentRequestData.RESIDENT_STATE"
                   ng-change="cdModel.documentChanged()"
                   ng-options="state as code for (code, state) in vm.statesList"></select>

Then it only displays the StateId instead of anything else. Whenever i reverse code and state so it's "state as code for (state, code) in vm.stateList" i cannot display anything, it's just a drop-down list of blanks (the correct # though!). It also doesn't display the properties through a repeat like this:

 <tr ng-repeat="st in vm.statesList">
            <td>Names:</td>
        {{st.stateList.StateName}}
        {{st.stateCode }}
           {{ st.stateId }}
    </tr>

My Question: How do i get the StateName's to display and have the StateCode be what gets used in the ng-options(returned)? Note: i'm not concerned w/ StateId AT ALL!

Lrrr
  • 4,755
  • 5
  • 41
  • 63
user1789573
  • 515
  • 2
  • 8
  • 23
  • Is that an array of objects or a named array? – tymeJV Oct 20 '14 at 21:00
  • It's an array of data. So, it could be considered an object because the language considers every entity (including arrays) to be objects. If you're asking if i did vm.stateList = new Object(); i did not. What i intialized it to was an array: vm.stateList = []; – user1789573 Oct 20 '14 at 21:02
  • What you should have is an array of objects, avoid named arrays in JavaScript...they're not meant to be. (Hopefully this explains better than I can http://stackoverflow.com/questions/8067590/associative-array-versus-object-in-javascript) – tymeJV Oct 20 '14 at 21:03
  • Well, i can't help what Json data comes back as. I'm hitting a SQL database...i'm not sure what you're trying to ask. Could you ask it in another way? – user1789573 Oct 20 '14 at 21:04
  • The data you get back is considered mal-formed and won't have the desired effect with `ng-repeat` - can you modify the return data from the server? – tymeJV Oct 20 '14 at 21:05
  • No...and i'm actually displaying similar data elsewhere on the page completely fine. It's also not considered mal-formed because i'm displaying the StateId, but nothing else. So...i can display data, just no the data i want. – user1789573 Oct 20 '14 at 21:09
  • But the repeat here wouldn't make any sense as there's no clear indication of when to start the repeater over - your data is just jammed into an array. – tymeJV Oct 20 '14 at 21:11
  • Yeah, the ng-repeat was to illustrate that i wasn't able to display any of the properties within the object array. It's the ng-options that is giving me issue. Also, the ng-repeat would make sense since i'm iterating over an array, which is what ng-repeat is for (iteration). Does that make sense? – user1789573 Oct 20 '14 at 21:13
  • Kind of... I still have an issue with that array - but, the real issue is probably that you're using the object syntax for your repeater (`k, v in o`) when you want the array syntax (`item in items`) - so it'd look like `state in stateList` - then you would use `state.stateId` - but I'm not sure this will work if you dont have an array of objects. – tymeJV Oct 20 '14 at 21:15
  • So...what are you saying for ng-options should be? – user1789573 Oct 20 '14 at 21:19

1 Answers1

0
ng-options="state.StateCode as state.StateName for state in vm.statesList"
user1789573
  • 515
  • 2
  • 8
  • 23