简体   繁体   中英

combobox and angularjs using ng-options

My data structure is following

{
    "Name": "Somename",
    "SchoolSeasons": [
        {
            "Id": "1",
            "Name": "2014/2015"            
        },
        {
            "Id": "2",
            "Name": "2013/2014"            
        }
    ]
}

using angularjs inside html view I want to render this year inside combobox for selection. Tried following

<div ng-repeat="seasson in data.SchoolSeasons">
   <select ng-model="seasson.Name" 
           ng-options="seasson.Name for seasson in session.Name">
   </select>
</div>

any idea?

Given:

     $scope.data = {
        "Name": "Somename",
        "SchoolSeasons": [{
          "Id": "1",
          "Name": "2014/2015"
        }, {
          "Id": "2",
          "Name": "2013/2014"
        }]
      };

Should just be as simple as:

<select ng-model="seasson.Name" ng-options="seasson.Name for seasson in data.SchoolSeasons">
  <option value="">-- choose season --</option>
</select>

Example here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM