最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - After making selection from an ui-select box, chosen option is not sticking (not visible) as selected - Stack Overf

programmeradmin3浏览0评论

I've created a plunker for this:

Select choices are there, but when you choose one, the ui-select is left blank. Potentially important note: I'm using this inside a directive (ui-bootstrap). As a side note to this - in the plunker there is no wrapping directive so that is not the culprit.

<ui-select search-enabled="true" ng-change="updateMedu()" style="width: 100%" ng-model="medications.chosenMedications.metadata.conceptGroup.conceptProperties">
    <ui-select-match placeholder="Please click to choose or start typing dosage value..">{{$item}}</ui-select-match>
    <ui-select-choices repeat="cp in medications.chosenMedications.metadata[key].conceptGroup[1].conceptProperties | filter: $select.search">
        {{cp.synonym}}
    </ui-select-choices>
</ui-select>

Manual mock of the dataset:

$scope.medications.chosenMedications.metadata = [
    {
        conceptGroup: [
            {
                conceptProperties: [
                   {synonym: "Item One"},
                   {synonym: "Item Two"},
                   {synonym: "Item Three"}
                ]
            },
            {
                conceptProperties: [
                    {synonym: "Item A"},
                    {synonym: "Item B"},
                    {synonym: "Item C"}
                ]
            }
         ]
     }
];

I've created a plunker for this: http://plnkr.co/edit/5nk4BnYoO52En7P6kPu9

Select choices are there, but when you choose one, the ui-select is left blank. Potentially important note: I'm using this inside a directive (ui-bootstrap). As a side note to this - in the plunker there is no wrapping directive so that is not the culprit.

<ui-select search-enabled="true" ng-change="updateMedu()" style="width: 100%" ng-model="medications.chosenMedications.metadata.conceptGroup.conceptProperties">
    <ui-select-match placeholder="Please click to choose or start typing dosage value..">{{$item}}</ui-select-match>
    <ui-select-choices repeat="cp in medications.chosenMedications.metadata[key].conceptGroup[1].conceptProperties | filter: $select.search">
        {{cp.synonym}}
    </ui-select-choices>
</ui-select>

Manual mock of the dataset:

$scope.medications.chosenMedications.metadata = [
    {
        conceptGroup: [
            {
                conceptProperties: [
                   {synonym: "Item One"},
                   {synonym: "Item Two"},
                   {synonym: "Item Three"}
                ]
            },
            {
                conceptProperties: [
                    {synonym: "Item A"},
                    {synonym: "Item B"},
                    {synonym: "Item C"}
                ]
            }
         ]
     }
];
Share Improve this question edited Oct 15, 2014 at 20:38 Rob J 6,6295 gold badges30 silver badges30 bronze badges asked Oct 15, 2014 at 15:51 developer10developer10 1,5003 gold badges15 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Just try the following code:

<ui-select theme="select2" search-enabled="true" style="width: 100%" 
        ng-model="medications.chosenMedications.metadata.conceptGroup.conceptProperties">
    <ui-select-match placeholder="Click to select or start typing...">
        {{$select.selected.synonym}}
    </ui-select-match>
    <ui-select-choices repeat="cp in medications.chosenMedications.metadata[0].conceptGroup[1].conceptProperties | filter: $select.search">
            {{cp.synonym}}
    </ui-select-choices>
</ui-select>

Your problem is that you try to show {{$item}} instead of {{$select.selected.synonym}}

Hope, this will resolve your problem.

Working demo: http://plnkr.co/edit/B3HTozs0MniWBpEj8L50?p=preview

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论