我正在尝试使用ngGrid来捕获数据。在$scope.myData
列的CellTemplate上输入输入时,我很难在提交时获得更新age
。
问题:
如何使用cellTemplate捕获数据并在sumbit上获取更新的$scope.myData
?
网格A
JS
$scope.myData = [{name: "Moroni", age: ""},
{name: "Tiancum", age: ""},
{name: "Jacob", age: ""},
{name: "Nephi", age: ""}];
$scope.gridOptions = {
data: 'myData',
selectedItems: $scope.mySelections,
multiSelect: true,
columnDefs: [
{field: 'name', displayName: 'Name'},
{field:'age', displayName:'Age', cellTemplate: '<input type="number" placeholder="Enter age" />'}
]
};
$scope.getUpdatedData = function () {
console.log($scope.myData);
$scope.updatedData = $scope.myData;
};
网格B 但是,没有一个cellTemplate
JS
// WITHOUT CELL TEMPLATE
$scope.myData2 = [{name: "Moroni", age: ""},
{name: "Tiancum", age: ""},
{name: "Jacob", age: ""},
{name: "Nephi", age: ""}];
$scope.gridOptions2 = {
data: 'myData2',
selectedItems: $scope.mySelections,
enableCellEditOnFocus: true,
multiSelect: true,
columnDefs: [
{field: 'name', displayName: 'Name'},
{field:'age', displayName:'Age'}
]
};
$scope.getUpdatedData2 = function () {
console.log($scope.myData2);
$scope.updatedData2 = $scope.myData2;
};
答案 0 :(得分:1)
如果你放
就可以了<input type="number" placeholder="Enter age" ng-input="COL_FIELD" ng-model="COL_FIELD" />
作为您的cellTemplate。我已更新your plunk以证明这一点。