第一次未选中单选按钮

时间:2019-05-08 09:41:35

标签: jquery angularjs jqgrid

我正在使用angularjs和Jqgrid,在一个表中,我有两列,其中一列具有单选按钮,另一列包含数字。 我已经实现了此配置以显示表格并在单选按钮上添加click事件。

    /*global appModule */
'use strict';

(appModule.lazy || appModule)
.service('ModalBusquedaNumeroDeViaGridSrv', ['$translate', function($translate) {

    function getOptions() {
        var options = {
            datatype: 'local',
            colNames: [
                '',
                $translate('datoRiesgoNuevo.DatosModalCatastralHogar.numerosDisponibles')
            ],
            colModel: [{
                name: 'selRadio',
                index: 'selRadio',
                align: 'center',
                width: 40,
                formatter: function(data, cell, obj) {
                    return '<input type=\"radio\" id=\"' + cell.rowId + '\" name=\"selRadio\" />';
                }
            }, {
                name: 'numerosDisponibles',
                index: 'numerosDisponibles',
                align: 'center',
                width: 400
            }],
            rownumbers: false,
            rowTotal: 20,
            rowList: [
                5,
                10,
                15
            ],
            loadonce: true,
            gridview: true,
            sortname: 'numerosDisponibles',
            viewrecords: true,
            sortorder: 'asc',
            footerrow: false,
            autowidth: true,
            shrinkToFit: true,
            height: '220',
            scrolloffset: 0,
            scroll: true
        };

        return options;

    }
    return {
        getOptions: getOptions
    }
}]);

我使用此服务获取选项,然后在控制器中将数据和选项传递给数组。 这是控制器。

drn.numerosVia = [{
    'sel': 'false',
    'numerosDisponibles': '10'
}, {
    'sel': 'false',
    'numerosDisponibles': '20'
}, {
    'sel': 'false',
    'numerosDisponibles': '30'
}];

drn.gridNumerosVia = {
    data: drn.numerosVia,
    options: ModalBusquedaNumeroDeViaGridSrv.getOptions()
};

$scope.$on('drn.gridNumerosViaSet', function(event, myGrid) {
    myGrid.jqGrid('setGridParam', {
        loadComplete: function(data) {
            var getColumnIndexByName = function(columnName) {
                    var cm = myGrid.jqGrid('getGridParam', 'colModel'),
                        i = 0,
                        l = cm.length;
                    for (; i < l; i++) {
                        if (cm[i].name === columnName) {
                            return i; // return the index
                        }
                    }
                    return -1;
                },
                i = getColumnIndexByName('selRadio');

            function changeMyModel(i, input) {

                var dataRow = i - 1;
                drn.gridNumerosVia.data[dataRow].sel = input.checked;
                $scope.$apply();
            }

            // nth-child need 1-based index so we use (i+1) below
            angular.element('tbody > tr.jqgrow > td:nth-child(' + (i + 1) + ') > input',
                this).click(function(e) {
                var rowId = angular.element(e.target).closest('tr').attr('id');
                changeMyModel(rowId, this);
            });
        }
    });
});

请记住,此表格显示在模式内部。 仅当我第一次单击单选按钮时才会出现此问题,一旦我第一次单击它们,它们就可以正常工作。

1 个答案:

答案 0 :(得分:0)

drn.numerosVia = [{
    '̶s̶e̶l̶'̶:̶ ̶'̶f̶a̶l̶s̶e̶'̶,̶
    'sel': false,
    'numerosDisponibles': '10'
}, {
    '̶s̶e̶l̶'̶:̶ ̶'̶f̶a̶l̶s̶e̶'̶,̶
    'sel': false,
    'numerosDisponibles': '20'
}, {
    '̶s̶e̶l̶'̶:̶ ̶'̶f̶a̶l̶s̶e̶'̶,̶
    'sel': false,
    'numerosDisponibles': '30'
}];

将选择内容设置为布尔值false,而不是字符串"false"

在JavaScript中,字符串"false"的值为truthy