为了账号安全,请及时绑定邮箱和手机立即绑定

JavaScript/ AngularJS:只有当我单击两次按钮时才会显示错误消息

JavaScript/ AngularJS:只有当我单击两次按钮时才会显示错误消息

收到一只叮咚 2022-08-27 15:25:08
我有一个angularJS视图,允许用户上传Excel数据并将其导入SQL服务器表。我添加了数据的客户端验证,但仅当我再次单击“上载/导入”按钮时,才会显示错误消息。我不确定代码中的哪个部分导致了此问题。是否可以寻求帮助以尝试解决此问题?我想我可能需要移动变量赋值的位置,但在哪里?$scope.Message我包括Javascript / angularjs代码和html视图。AngularJS//Parse Excel Data   $scope.ParseExcelDataAndSave = function () {    var file = $scope.SelectedFileForUpload;    if (file) {        var reader = new FileReader();        reader.onload = function (e) {            var filename = file.name;            // pre-process data            var binary = "";            var bytes = new Uint8Array(e.target.result);            var length = bytes.byteLength;            for (var i = 0; i < length; i++) {                binary += String.fromCharCode(bytes[i]);            }            // call 'xlsx' to read the file            var data = e.target.result;            var workbook = XLSX.read(binary, { type: 'binary', cellDates: true, cellStyles: true });            var sheetName = workbook.SheetNames[0];            var excelData = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);            exceljsonObj = excelData;            var errors = [];            var rowCounter = 1;            for (var j = 0; j < exceljsonObj.length; j++) {                var xdata = exceljsonObj[j];                if (xdata['Meeting ID'] === undefined || xdata['MeetingID'] === undefined) {                    errors.push('Row: ' + rowCounter + ' is missing the Meeting ID value.' +                                ' Please, verify that the data you are trying to upload meets the required criteria, ' +                                'and then try to upload your file again.');                }};
查看完整描述

1 回答

?
胡说叔叔

TA贡献1804条经验 获得超8个赞

$scope摘要问题。分配$scope后调用 $scope.apply()。消息


if (errors.length > 0) {

            $scope.Message = 'Please, verify that the file you are trying to upload is correctly formatted, \n ' +

                                'and that the data it contains, meets the expected criteria, then click the upload button again. \n Thank you!'


    $scope.$apply();

 }


查看完整回答
反对 回复 2022-08-27
  • 1 回答
  • 0 关注
  • 78 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信