简体   繁体   English

具有选择单元格的Angularjs ng-grid未被选择为正确的值

[英]Angularjs ng-grid with select cell not seleceted to right value

I am trying to build a table where one of the columns is selected and I want to select the option with the value that I get from server. 我正在尝试构建一个表,其中一个列被选中,我想选择具有从服务器获取的值的选项。 I am getting 4 from the server but the the one that is selected is the first option. 我从服务器获得4,但选择的是第一个选项。

$scope.lotteryOptions = {
        data: 'myData',
        enableColumnResize: true,
        keepLastSelected: false,
        enableRowSelection: false,
        columnDefs: [{field: 'field1', displayName: 'field1'},
             {field: 'Status', displayName: 'Status', cellTemplate: selectTableTemplate, enableCellEdit: true},
    };

 var selectTableTemplate = "<select ng-selected=\"{{row.getProperty('Status')}}\">         <option value='1' class='ng-binding'>" + 1+ "</option>" +
                           "<option value='2' class='ng-binding'>" + 2 + "</option>" +
                           "<option value='3' class='ng-binding'>" + 3 + "</option>" +
                           "<option value='4' class='ng-binding'>" + 4 + "</option>" +
                           "<option value='5' class='ng-binding'>" + 5 + "</option>" +
                    "<option value='6' class='ng-binding'>" + 6 + "</option></select>";

the html result is: html结果是:

 <select ng-selected="4">...</select> 

but is not select the 4 choice 但不是选择4选择

ng-selected should be applied to the option tags, not select (see the docs ) ng-selected应该应用于option标签,而不是select (参见文档

$scope.lotteryOptions = {
    columnDefs: [
        {field: 'field1'},
        {field: 'Status', cellTemplate: selectTableTemplate, enableCellEdit: true}
    ],
    data: 'myData',
    enableColumnResize: true,
    enableRowSelection: false,
    keepLastSelected: false

};

 var selectTableTemplate = '<select>' +
                           '  <option value="1" class="ng-binding" ng-selected="COL_FIELD == 1">' + 1 + '</option>' +
                           '  <option value="2" class="ng-binding" ng-selected="COL_FIELD == 2">' + 2 + '</option>' +
                           '  <option value="3" class="ng-binding" ng-selected="COL_FIELD == 3">' + 3 + '</option>' +
                           '  <option value="4" class="ng-binding" ng-selected="COL_FIELD == 4">' + 4 + '</option>' +
                           '  <option value="5" class="ng-binding" ng-selected="COL_FIELD == 5">' + 5 + '</option>' +
                           '  <option value="6" class="ng-binding" ng-selected="COL_FIELD == 6">' + 6 + '</option>' +
                           '</select>';

ng-selected is already an angular attribute so there is no need to interpolate {{ }} : ng-selected已经是一个角度属性,因此无需插入{{ }}

var selectTableTemplate = "<select>         <option ng-selected=\"row.getProperty('Status') == 1\" value='1' class='ng-binding'>" + 1 + "</option>" +
                           "<option ng-selected=\"row.getProperty('Status') == 2\" value='2' class='ng-binding'>" + 2 + "</option>" +
                           "<option ng-selected=\"row.getProperty('Status') == 3\" value='3' class='ng-binding'>" + 3 + "</option>" +
                           "<option ng-selected=\"row.getProperty('Status') == 4\" value='4' class='ng-binding'>" + 4 + "</option>" +
                           "<option ng-selected=\"row.getProperty('Status') == 5\" value='5' class='ng-binding'>" + 5 + "</option>" +
                    "<option ng-selected=\"row.getProperty('Status') == 6\" value='6' class='ng-binding'>" + 6 + "</option></select>";

Note: This also assumes that Status is a value, not an object. 注意:这也假定Status是值,而不是对象。

Update: ng-selected is not an attribute of select . 更新: ng-selected不是select的属性。 It is only an attribute of option . 它只是option一个属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM