AngularUI - ui-选择多个值未正确显示

时间:2016-09-09 19:11:22

标签: angularjs json angular-ui

我有一个angular-ui下拉多选,不能正确显示值。输入绑定框形成一个普通框而不评估我的$item表达式。类似的东西:

No Expression Evaluation

HTML:

<ui-select 
    multiple
    ng-model ="allPlatforms.selected" >
    <ui-select-match  placeholder="Start Typing...">{{$item.allPlatforms}}</ui-select-match>
    <ui-select-choices repeat="item in (allPlatforms | filter: $select.search) track by item">
        {{item.allPlatforms}}
    </ui-select-choices>
    <ui-select-no-choice>
        Dang! Sorry bro. Couldn't find
    </ui-select-no-choice>
</ui-select>

我从服务器生成并调用了两个JSON文件。

PFtypes JSON文件看起来像 {"allpftypes":["pf1", "pf2"...]}

Controller JS

$scope.name={};
$scope.allPlatforms=[];

$http.get('server.com/'+$scope.num).then(function(response){
        $scope.name = response.data;
        $scope.allPlatforms.selected = [$scope.allPlatforms[0]];
//I will want to do [$scope.allPlatforms[$scope.name.platform_name]] but I've ignored that for now;
});
$http.get('server.com/pftypes').then(function(response){
        $scope.allPlatforms = response.data.allpftypes;
    });

如果我删除了多个属性并进行$ select更改,它就可以正常工作。我不确定我犯了什么可怕的错误。在Angular还是学习新手。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

刚才意识到我已经在allplatforms数组中并完全忽略了那一点。它应该只是$item而不是$item.allplatforms

<ui-select 
    multiple
    ng-model ="allPlatforms.selected" >
  <ui-select-match  placeholder="Start Typing...">{{$item}}</ui-select-match>
  <ui-select-choices repeat="item in (allPlatforms | filter: $select.search) track by item">
    {{item}}

     //or
    //<div ng-bind-html="item | highlight: $select.search"></div>

    </ui-select-choices>
    <ui-select-no-choice>
      Dang! Sorry bro. Couldn't find
    </ui-select-no-choice>
</ui-select>

将此作为答案,以防有人遇到类似的ui-select-multiple问题。和平!

欢迎任何进一步的变化:)