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选择
2 个解决方案
#1
2
ng-selected
should be applied to the option
tags, not select
(see the docs)
ng-selected应该应用于选项标签,而不是选择(参见文档)
$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>';
#2
0
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
. It is only an attribute of option
.
更新:ng-selected不是select的属性。它只是选项的一个属性。
#1
2
ng-selected
should be applied to the option
tags, not select
(see the docs)
ng-selected应该应用于选项标签,而不是选择(参见文档)
$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>';
#2
0
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
. It is only an attribute of option
.
更新:ng-selected不是select的属性。它只是选项的一个属性。