javascript - 带有未选择正确值的选择单元格的 Angularjs ng-grid

标签 javascript jquery html angularjs ng-grid

我正在尝试构建一个表,其中选择了其中一列,并且我想选择具有从服务器获取的值的选项。 我从服务器获得 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>";

html 结果是:

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

但不是选择第4个选项

最佳答案

ng-selected 应该应用于 option 标签,而不是 select (参见 the docs )

$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>';

关于javascript - 带有未选择正确值的选择单元格的 Angularjs ng-grid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20218625/

相关文章:

javascript - Ajax 在循环中成功设置全局变量

javascript - 从二进制字符串中读取可变长度位

javascript - jQuery:访问具有特定日期和文本的一串数字的总和

javascript - jQuery/PHP - 将数据从 JS 传递到 PHP 以对数据库执行删除

javascript - 我可以将 hashChange 监听器设置为 iFrame src 吗?

html - child 走出父元素

html - 你如何重新缩放 HTML/CSS 中的图像以具有相同的高度?

jquery - BackboneJS 单页站点 : Attaching and Cleaning Up Views

php - 使用 Jquery/Bootstrap 删除标签标签/添加输入文本框

javascript - 将 RSS 转换为 HTML