簡體   English   中英

具有選擇單元格的Angularjs ng-grid未被選擇為正確的值

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

我正在嘗試構建一個表,其中一個列被選中,我想選擇具有從服務器獲取的值的選項。 我從服務器獲得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 (參見文檔

$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已經是一個角度屬性,因此無需插入{{ }}

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>";

注意:這也假定Status是值,而不是對象。

更新: ng-selected不是select的屬性。 它只是option一個屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM