角度多选下拉列表

时间:2016-05-30 07:57:50

标签: angularjs bootstrap-multiselect

在角度多重选择中,我想在选项中显示Id值。现在我只显示标签价值。

例如:  HTML:

JS:$ scope.example14data = [{         “label”:“Alabama”,             “id”:“AL”     }

当前结果:阿拉巴马州

预期成果:  Alabama AL

请参考以下js小提琴 Js Fiddlehttps://jsfiddle.net/michaeldeongreen/22et6sao/9/

先谢谢

2 个答案:

答案 0 :(得分:0)

首先,您编辑getPropertyForObject功能

$scope.getPropertyForObject = function (object, property, property2) {
    if (angular.isDefined(object) && object.hasOwnProperty(property)) {
       return object[property] + (object[property2]?(" "+object[property2]):"");
    }

    return '';
};

然后改变这个

if (checkboxes) {
                template += '<div class="checkbox"><label><input class="checkboxInput" type="checkbox" ng-click="checkboxClick($event, getPropertyForObject(option,settings.idProp))" ng-checked="isChecked(getPropertyForObject(option,settings.idProp))" /> {{getPropertyForObject(option, settings.displayProp, settings.displayProp2)}}</label></div></a>';
            } else {
                template += '<span data-ng-class="{\'glyphicon glyphicon-ok\': isChecked(getPropertyForObject(option,settings.idProp))}"></span> {{getPropertyForObject(option, settings.displayProp, settings.displayProp2)}}</a>';
            }

$scope.settings = {
                dynamicTitle: true,
                scrollable: false,
                scrollableHeight: '300px',
                closeOnBlur: true,
                displayProp: 'label',
                displayProp2: 'id',
                idProp: 'id',
                externalIdProp: 'id',
                enableSearch: false,
                selectionLimit: 0,
                showCheckAll: true,
                showUncheckAll: true,
                closeOnSelect: false,
                buttonClasses: 'btn btn-default',
                closeOnDeselect: false,
                groupBy: $attrs.groupBy || undefined,
                groupByTextProvider: null,
                smartButtonMaxItems: 0,
                smartButtonTextConverter: angular.noop
            };

答案 1 :(得分:0)

我找不到结果格式化程序。我有一个解决方法

将返回结果

{“label”:“Alabama”,“id”:“AL”,“已解析”:“Alabama AL”}

https://jsfiddle.net/22et6sao/477/

$scope.example14model = [];
$scope.example14settings = {
    scrollableHeight: '200px',
    scrollable: true,
    enableSearch: true,
    externalIdProp : ''
};

$scope.EXeVENTS = {
   onItemSelect : function(item){
     item.parsed = item.label + ' ' + item.id
   }
}

希望这是好的。