Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 角度ui网格-下拉选择显示Id_Jquery_Angularjs_Angular Ui Grid - Fatal编程技术网

Jquery 角度ui网格-下拉选择显示Id

Jquery 角度ui网格-下拉选择显示Id,jquery,angularjs,angular-ui-grid,Jquery,Angularjs,Angular Ui Grid,我用的是角的。当我在网格中有下拉列表时面临问题 我在下拉列表中使用了以下代码:- objCombos = $scope.getComboValues('DEPARTMENT'); $scope.gridOptions.columnDefs.push({ field: fieldName.toUpperCase(), displayName: displayName, columnType: 'columnDb', editableCellTemplate: 'ui-grid/dropdownE

我用的是角的。当我在网格中有下拉列表时面临问题

我在下拉列表中使用了以下代码:-

objCombos = $scope.getComboValues('DEPARTMENT');

$scope.gridOptions.columnDefs.push({
field: fieldName.toUpperCase(), displayName: displayName,
columnType: 'columnDb',
editableCellTemplate: 'ui-grid/dropdownEditor',
editDropdownValueLabel: 'DEPARTMENT',
editDropdownOptionsArray: objCombos,
name: fieldName.toUpperCase()
});
下拉列表的数组如下所示:-

当我选择并更改下拉列表值(从Branch1到Branch2)时,在更改该值后,它会在本例2中的下拉列表中显示所选值的id


我只需添加以下属性即可解决此问题:-

editDropdownIdLabel: 'DEPARTMENT',

我只需添加以下属性即可解决此问题:-

editDropdownIdLabel: 'DEPARTMENT',
如果确实不需要id,则可以将editDropdownIdLabel设置为与editDropdownValueLabel匹配。也就是说,您的底层数据结构存储字符串Branch1、Branch2,而不是整数1,2

如果不是这样,则使用自定义过滤器。我最近遇到过这样一种情况:一周中的几天作为整数1-7存储在后端,但用户希望在网格中看到全名字符串。 下面是我的解决方案-针对此示例进行了修改:

angular.module('myApp').filter("branchFilter", function() {
    var vals = ["Branch1", "Branch2"];
    return function(id) {
        var i = id-1, ret = "?";
        if(i>=0 && i< vals.length) {
            ret = vals[i];
        }
        return ret;
    };
});
然后告诉自定义筛选器如何使用这些值:

angular.module('myApp').filter("comboFilter", function(ComboValues) {
    return function(id, comboName, idName, valName) {
        idName = idName || "id";      //optional - defaults to 'id'
        valName = valName || "value"; //optional - defaults to 'value'
        var opts = ComboValues[comboName];
        if(angular.isArray(opts)) {
            var ret = id; //default return value if no match found
            opts.some(function(opt) {  //look for matching option
                if(opt[idName]===id) {
                    ret = opt[valName];
                    return true; //break
                }//else keep looking
            });
            return ret;
        } else {
            return comboName+ " not an array";
        }
    };
});
然后在列defs中,使用: cellFilter:comboFilter:'branch':'id':'value' 或者如果默认值正常: cellFilter:comboFilter:“分支”

注意,在本例中,参数需要额外的引号,因此过滤器将其视为字符串而不是范围变量。也就是说:comboFilter:'branch'不是comboFilter:branch。

设置editDropdownIdLabel以匹配editDropdownValueLabel对于不真正需要id的情况是可以的。也就是说,您的底层数据结构存储字符串Branch1、Branch2,而不是整数1,2

如果不是这样,则使用自定义过滤器。我最近遇到过这样一种情况:一周中的几天作为整数1-7存储在后端,但用户希望在网格中看到全名字符串。 下面是我的解决方案-针对此示例进行了修改:

angular.module('myApp').filter("branchFilter", function() {
    var vals = ["Branch1", "Branch2"];
    return function(id) {
        var i = id-1, ret = "?";
        if(i>=0 && i< vals.length) {
            ret = vals[i];
        }
        return ret;
    };
});
然后告诉自定义筛选器如何使用这些值:

angular.module('myApp').filter("comboFilter", function(ComboValues) {
    return function(id, comboName, idName, valName) {
        idName = idName || "id";      //optional - defaults to 'id'
        valName = valName || "value"; //optional - defaults to 'value'
        var opts = ComboValues[comboName];
        if(angular.isArray(opts)) {
            var ret = id; //default return value if no match found
            opts.some(function(opt) {  //look for matching option
                if(opt[idName]===id) {
                    ret = opt[valName];
                    return true; //break
                }//else keep looking
            });
            return ret;
        } else {
            return comboName+ " not an array";
        }
    };
});
然后在列defs中,使用: cellFilter:comboFilter:'branch':'id':'value' 或者如果默认值正常: cellFilter:comboFilter:“分支”


注意,在本例中,参数需要额外的引号,因此过滤器将其视为字符串而不是范围变量。也就是说:comboFilter:“branch”不是comboFilter:branch。

那么你的问题是什么?问题是为什么在下拉列表中选择后显示id而不是值。那么你的问题是什么?问题是为什么在下拉列表中选择后显示id而不是值。