【问题标题】:Angular Multiselect Dropdown角度多选下拉
【发布时间】:2016-05-30 16:50:15
【问题描述】:

在 angular multislect 中,我想在选项中显示 Id 值。现在我只显示标签值。

例如: HTML :

JS : $scope.example14data = [{ “标签”:“阿拉巴马州”, “id”:“AL” }

当前结果:阿拉巴马州

预期结果: 阿拉巴马州

请参考下面的 js fiddle Js Fiddle : https://jsfiddle.net/michaeldeongreen/22et6sao/9/

提前致谢

【问题讨论】:

    标签: angularjs bootstrap-multiselect


    【解决方案1】:

    首先,你编辑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
                };
    

    【讨论】:

    • 完美!非常感谢.. 非常感谢您的快速回复。
    • 请批准我的回答
    【解决方案2】:

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

    返回结果

    {"label":"Alabama","id":"AL","parsed":"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
       }
    }
    

    希望这没问题。

    【讨论】:

      猜你喜欢
      • 2018-09-25
      • 2016-12-30
      • 2019-08-03
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      相关资源
      最近更新 更多