0

Do you guys know of a way to have md-autocomplete select based on the value of one object parameter?

I want to preselect some data in my autocompletes on loading of my data.

So for instance the data I get from my server is:

{"building": "0015", "room": "0113", "available": true}

But the buildings list of my autocomplete might look like this:

[{"Value": "0015", "DisplayValue": "Offices"},{"Value": "0813", "DisplayValue": "factory"}]

Is there a way to have my autocomplete preselect the "Offices" building if I pass it the "number" parameter?

My html looks like this:

<md-autocomplete ng-disabled="!vm.edit.value" md-selected-item="vm.activityData.building"
                         md-items="item in vm.getList('Buildings')"
                         md-search-text="vm.autocompleteTexts.Buildings"
                         md-selected-item-change="vm.setAutocompleteValue('building')"
                         md-item-text="item.DisplayValue" md-min-length="0"
                         md-no-cache="true" md-select-on-match="true"
                         md-delay="100"
                         md-floating-label="Building"
                         md-dropdown-position="bottom">
            <md-item-template>
                <span>{{item.DisplayValue}}</span>
            </md-item-template>
            <md-not-found>
                No values found
            </md-not-found>
        </md-autocomplete>

getList is like this

getList(listname: string): any[] {
        return this.serverdata.Lists[listname].filter(
            (item) => {
                return item.DisplayValue.toLowerCase().indexOf(this.autocompleteTexts[listname].toLowerCase()) >= 0;
            });
    }

setAutocompleteValue doesn't do anything yet, but it exists, this will be used for some autocompletes where they have to populate other fields after changing selections.

Since "item in array" is standard angular expression, I thought I could expand it with track by, but that doesn't work sadly...

Firenter
  • 301
  • 3
  • 14

0 Answers0