angularjs ui-select, чтобы захватить только ключ, а не значение в выпадающем живом поиске

Я фильтрую раскрывающееся меню, вводя его в поле и вводя ключ в свою модель. Он работает нормально! Однако проблема в том, что когда я печатаю, выбор не сужается. в чем проблема?

захват ключа, но не поиск в реальном времени!

<div class="form-group" >
    <label translate="data.continent">
        my continents
    </label>
    <ui-select ng-model="myModel.continent" ng-change="continentSelect()" theme="bootstrap">
        <ui-select-match placeholder="Select in the list...">
            {{$select.selected.value}}
        </ui-select-match>
        <ui-select-choices repeat="r.key as r in data.continent.list track by $index | filter: {'key': $select.search}">
            <div ng-bind-html="r.value | highlight: $select.search"></div>
        </ui-select-choices>
    </ui-select>
</div>

однако здесь выбор сужается, но модель фиксирует как ключ, так и значение, чего я не хочу.

поиск в реальном времени работает нормально, но захватывает как ключ, так и значение

<div class="form-group" >
    <label translate="data.continent">
        Continent
    </label>
    <ui-select ng-model="myModel.continent" ng-change="continentSelect()" theme="bootstrap">
        <ui-select-match placeholder="Select in the list...">
            {{$select.selected.value}}
        </ui-select-match>
        <ui-select-choices repeat="r in data.continent.list | filter: $select.search ">
            <div ng-bind-html="r.value | highlight: $select.search"></div>
        </ui-select-choices>
    </ui-select>
</div>

моя структура данных выглядит так:

"list" : [
        {"key" : "continent1", "value" : "Americas"},
        {"key" : "continent2", "value" : "Europe"},
        {"key" : "continent3", "value" : "Africa"}]

Конечная цель:

конечной целью является поиск в реальном времени и передача ключа, например, «continent1» в ng-change="continentSelect()".


person cplus    schedule 11.11.2016    source источник


Ответы (1)


замените второй код следующим, просто добавив .key:

<ui-select-choices repeat="r.key as r in data.continent.list | filter: $select.search">
person Marcel    schedule 11.11.2016