无法使用filesaver.js保存文件

时间:2018-01-31 07:37:43

标签: angularjs

我的代码如下

<div id="createConfigManagementDivId" 
class="panel-portal">

<div >
<button ng-click="exportData()" ng-show="(items|filter:{selected: true}).length">Export</button>
<br />
<table width="100%">
        <thead>
            <tr>
                <th></th>
                <th>Name</th>
                <th>Date</th>
                <th>Terms</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="item in items">
                <td><input type="checkbox" ng-model="item.selected" /></td>
                <td>{{item.Name}}</td>
                <td>{{item.Date}}</td>
                <td><span ng-repeat="term in item.Terms">{{term}}{{!$last?', ':''}}</span></td>
            </tr>
        </tbody>
    </table>
<div id="exportable" style="display:none">
    <table width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Date</th>
                <th>Terms</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="item in items|filter:{selected: true}">
                <td>{{item.Name}}</td>
                <td>{{item.Date}}</td>
                <td><span ng-repeat="term in item.Terms">{{term}}{{!$last?', ':''}}</span></td>
            </tr>
        </tbody>
    </table>
</div>

</div>


<script type="text/javascript" src="jsp/resources/framework//Blob.js"></script>
<script type="text/javascript" src="jsp/resources/framework//FileSaver.js"></script> 
    <script type="text/javascript"
        src="jsp/resources/framework/ConfigMgmtController.js"></script>


controller.js
threeGppHssApp
        .controller(
                'configMgmtController',
                [
                        '$scope',
                        '$http',
                        '$stateParams',
                        '$filter',
                        '$window',
                        function($scope, $http,$stateParams,$filter,$window) {
                            console.log("Calling controller");


                            $scope.items = [{
        "Name": "ANC101",
            "Date": "10/02/2014",
            "Terms": ["samsung", "nokia", "apple"]
    }, {
        "Name": "ABC102",
            "Date": "10/02/2014",
            "Terms": ["motrolla", "nokia", "iPhone"]
    }]

                            $scope.exportData = function () {
                                var blob = new Blob([document.getElementById('exportable').innerHTML], {
                                    type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
                                });
                                saveAs(blob, "Report.xls");
                            };




                        }]);

然后我下载了blob.js和FileSaver.js并复制到路径sp / resources / framework /。

但是当我运行上面的代码时出现错误,因为File:FileSaver.js上的语法错误行:1,列:1

并且由于错误80020101而无法完成操作。

不确定为什么fileSaver.js会抛出错误?能帮我解决一下这个问题吗

0 个答案:

没有答案