简体   繁体   中英

AngularJS ng-repeat of array with a filter

I have an object (lets call it 'elements') like this one

[
{name: 'name1', columns: ['col1', 'col2', 'col3']},
{name: 'name2', columns: ['col4', 'col5', 'col6']},
{name: 'name3', columns: ['col7', 'col8', 'col9']},
]

I want to build a angular select object with the data from the columns property of the object filtered by the name

      <md-select
        name="selectedColumn"
        ng-model="selectedColumn"
        required
        placeholder="Column"
        ng-model-options="{trackBy: '$value._id'}">
        <md-option ng-repeat="elt in elements | filter: {name: selectedElt} " ng-value= "{{ elt }}" >
          <span class="item-title">
            <span>{{elt}}</span>
          </span>
        </md-option>
      </md-select>

The problem is that i get the full object and i do not know how to set the filter to loop over columns property only. For exemple, if i select 'name2' for selectedElt (it's another select element), i want my object 'selectedColumn' to be refreshed with 'col4', 'col5' and 'col6'

Thank you

Set a variable in your controller, like $scope.mySelectedElt and when you select name2 set that variable to that element object with ng-change. Then on your other select element (selectedElt, you said it was) do an ng-repeat for column in columns.

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