angularjs - 从 UI-Grid onblur 获取文本框值
问题描述
我想获取在 UI-Grid 中模糊事件的文本框中输入的值。我无法获取触发事件的值,但无法获取如何获取文本框值的逻辑。可以帮助弄清楚。
这是代码:
$scope.gridOptions = {
headerTemplate: 'header-template.html',
showColumnFooter: true,
columnDefs: [{ name: 'H', width: '15%' }, { name: 'H1', width: '30%' }],
data: [
{ H: "", H1: "Brand name" },
{ H: " ", H1: "Molecule" },
{ H: "Product Details ", H1: "Therapeutic area" },
{ H: " ", H1: "Targeted indication " },
{ H: " ", H1: "Estimated size of the patient population (in your market) " }
],
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
gridApi.core.on.renderingComplete(gridDrawn());
},
};
$scope.gridOptions.columnDefs.push({
name: 'H2', enableCellEdit: false,
field: "colButton", displayName: "Push Me",
//aggregationType: uiGridConstants.aggregationTypes.sum,
aggregationHideLabel: true,
cellTemplate: '<div><input type="Number" placeholder="Enter Number" onblur="calculateTotal()" style="width:90%" /></div>',
rowTemplate: '<div>Hai</div>',
width: '10%',
footerCellTemplate: '<div class="ui-grid-cell-contents" >Total: {{col.getAggregationValue() | number:2 }}</div>'
});
function calculateTotal() {
alert("Hello");
gridApi.edit.on.afterCellEdit($scope, function (rowEntity, colDef, newValue, oldValue) {
$scope.msg.lastCellEdited = 'edited row id:' + rowEntity.id + ' Column:' + colDef.name + ' newValue:' + newValue + ' oldValue:' + oldValue;
$scope.$apply();
});
}
解决方案
在范围上定义一个变量,例如:-
$scope.textboxValue = '';
然后将变量添加到ng-model
单元格模板的,如下所示
cellTemplate: '<div><input type="Number" ng-model="textboxValue" placeholder="Enter Number" onblur="calculateTotal()" style="width:90%" /></div>'
您的文本框值将可在函数中访问
$scope.calculateTotal = function () {
console.log($scope.textboxValue);
//other code
}
推荐阅读
- php - 如何从表数据库中计算平均值
- python - 使用 numpy.save 保存对象列表。然后删除包含每个对象的类的包
- magento2 - Magento 2.1.10:带有 ul li 的光滑滑块
- hyperledger-fabric - Hyperledger Fabric:在单个通道中加密分类帐数据
- amazon-web-services - Ansible - ec2 标签替换为变量
- node.js - 在某个浏览器中运行 create-react-app
- angularjs - Angular 6 中的 $scope.$apply() 等价物是什么?
- reactjs - React 使用按钮激活组件
- percona - 启动 Percona XTradb 集群的死节点
- android - Android 上的 MP4 Muxed 跳过最后一帧,但仅在某些应用程序中