gpt4 book ai didi

javascript - 数组数据显示在控制台中,但是当我在 html 中打印时,它没有在 angularjs 中显示空数组

转载 作者:行者123 更新时间:2023-11-29 15:17:21 25 4
gpt4 key购买 nike

我正在从一个文件中获取数据,然后将数据推送到数组。数组数据可以在控制台中查看,但该数据未显示在 html 页面中。如果我使用任何按钮,那么我就可以在 html 页面中看到该数据。

var app = angular.module('xlsxApp', []);
app.controller('xlsxCtrl', ['$scope', function($scope) {
$scope.finaldata = [];
$scope.UploadFiles = function(files) {
var f = files[0];
var reader = new FileReader();
reader.readAsBinaryString(f);
reader.onload = function(e) {
var data = e.target.result;
/*Converts the excel data in to object*/
var workbook = XLSX.read(data, {
type: 'binary'
});
/*Gets all the sheetnames of excel in to a variable*/
var sheet_name_list = workbook.SheetNames;
/*This is used for restricting the script to consider only first sheet of excel*/
sheet_name_list.forEach(function(y) { /*Iterate through all sheets*/
/*Convert the cell value to Json*/
var exceljson = XLSX.utils.sheet_to_json(workbook.Sheets[y]);
$scope.finaldata = exceljson;
console.log("finaldata :: ", $scope.finaldata);
});
}
}
$scope.test = function() {
console.log("finaldata :: ", $scope.finaldata);
}

}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.7.7/xlsx.core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xls/0.7.4-a/xls.core.min.js"></script>
</head>

<body ng-app="xlsxApp" ng-controller="xlsxCtrl">
<div class="container">
<div class="form-inline">
<input type="file" class="form-control" name="file" id="excelfile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" onchange="angular.element(this).scope().UploadFiles(this.files)" />

</div>
<button ng-click="test()">preview</button>
{{finaldata[0]}}
</div>
</body>

最佳答案

你在控制台中得到对象而不是数组。所以,在 html 中你绑定(bind) {{finaldata}}/如果你想要值 {{finaldata['C']}}

关于javascript - 数组数据显示在控制台中,但是当我在 html 中打印时,它没有在 angularjs 中显示空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47826882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com