【发布时间】:2020-12-16 06:54:46
【问题描述】:
我正在做一个项目,我试图在 UI 网格中添加一个下拉列表,这些下拉列表的值应该直接来自数据库。我怎样才能实现这个功能?并添加代码和html
这是我实现的代码
控制器 JS
function
fetchData ()
{
$http({
url: "api/GetAllpattern",
method: 'GET',
dataType: 'json',
headers: { "Content-Type": "application/json" }
}).then(function (result) {
if (result) {
$scope.gridOptions.data = result.data;
}});}
$scope.gridOptions = {
rowHeight: 38,
enableFullRowSelection: true,
multiSelect: true,
columnDefs: [
{ name: 'Slno' },
{ name: 'Name', type: 'number' },
{
name: 'Pattern',
// editableCellTemplate: 'uiSelect',
cellFilter: 'mapGender',
enableCellEdit: true,
editType: 'dropdown',
editableCellTemplate: 'ui-grid/dropdownEditor',
editDropdownValueLabel: 'displayName',
editDropdownValueLabel: 'Pattern', editDropdownOptionsArray: [
{ id: 1, gender: 'male' },
{ id: 2, gender: 'female' },
],
editDropdownValueLabel: 'type',
},
]};
}
HTML 标记
<div ui-grid="gridOptions"
ui-grid-selection
ui-grid-edit
class="grid">
【问题讨论】: