1

我正在使用剑道从客户端上传文件,加载时一切都按预期工作,但是当我们上传文件时,我有与 url 相关的问题,当文件加载成功时,我在配置中使用 url,我有来自服务器的响应。

如何使用剑道异步 saveUrl 方法从响应中提取数据?

main.html

<div class="form-group col-md-6">
    <div class="col-md-6">
        <label for="prcFileUploadField">File:</label>
    </div>
    <div class="col-md-6">
        <input name="file" type="file" kendo-upload="fileAttachment" k-upload="addMorePostParameters" k-success="onSuccess" k-error="onError" k-options="fileAttachmentOptions" k-select="onSelect" k-remove="onUploadRemove" />
    </div>
</div>

ctrl.js

angular.module('App').controller('PrcUploadCtrl',function($scope,$timeout,$rootScope,prcUploadConfig){
    'use strict';
    var fileData = [];
    $scope.fileAttachmentOptions = prcUploadConfig.fileAttachmentConfig;

    $scope.prcUploadGridOptions = prcUploadConfig.getPrcUploadDataGrid;
    prcUploadConfig.getPrcUploadDataGrid.dataSource='';

    $scope.onSelect = function (e) {
        fileData = e.files;
        var message = $.map(e.files, function(file) { return file.name; }).join(", ");
        console.log(message);
        console.log(JSON.stringify(fileData));
    };

    //if error 
    $scope.onError = function() {
        console.log("loggin error");
        $timeout(function () {
            var filesToBeRemoved = $scope.fileAttachment.wrapper.find('.k-file');
            $scope.fileAttachment._removeFileEntry(filesToBeRemoved);
        },5000);
    }
});

配置.js

fileAttachmentConfig: {
  async: {
      saveUrl: 'app/upload/uploadAttch',
      removeUrl: 'remove',
      removeVerb: 'DELETE',
      autoUpload: false
  },
  template: '<span class=\'file-name-heading\'>Name:</span> <span>#=name#</span><button type=\'button\' class=\'k-upload-action\'></button>'
}
4

1 回答 1

2

您始终可以从成功的请求中获得响应正文,如下所示:

$scope.onSuccess = function(e) {
    var response = e.response;
    //...
}
于 2015-11-20T06:46:15.120 回答