2014-03-26 5 views
1

내 각도/레일 앱에서 각도 파일 업로드 보석을 사용하여 스프레드 시트를 업로드합니다. https://github.com/danialfarid/angular-file-upload각도가 반환 된 데이터에 액세스 할 수 없습니다.

스프레드 시트를 Rails 백엔드로 전달하고 데이터를 처리하고 JSON 배열을 반환합니다.

파일 위로를 전달하는 각도 코드는 이것이다 :

$scope.submitForm = function() { 
    console.log('submit upload2'); 
    return $scope.upload = $upload.upload({ 
    url: '/api/batches/spreadsheet_upload.json', 
    data: { 
     id: 99, 
     assembly: "xy" 
    }, 
    file: $scope.file 
    }).success(data, status, headers, config)(function() { 
     debugger 
    $scope.selector.tabledata = data; 
    $scope.uploaded = true; 
    }); 
}; 

레일 파일을 받아 처리합니다. 내가 JSON 렌더링 로 반환하는 것을 시도하고있다 : {데이터 : spreadsheet_data}

def spreadsheet_upload 
    Rails.logger.debug("here params: #{params}") 
    spreadsheet = nil 
    case File.extname(params[:file].original_filename) 
    when '.csv' then spreadsheet = Roo::CSV.new(params[:file].path) 
    when '.xls' then spreadsheet = Roo::Excel.new(params[:file].path, nil, :ignore) 
    when '.xlsx' then spreadsheet = Roo::Excelx.new(params[:file].path, nil, :ignore) 
    else raise "Unknown file type: #{file.original_filename}" 
    end 

    spreadsheet_header = spreadsheet.row(1) 
    spreadsheet_data = [] 

    (2..spreadsheet.last_row).each do |i| 
    row = Hash[[spreadsheet_header, spreadsheet.row(i)].transpose] 
    spreadsheet_data.push(row) 
    end 
    render json: {data: spreadsheet_data} 
end 

크롬의 네트워크 탭은 데이터가 레일 서버에서 반환 된 나를 보여 주지만, 각도 무엇을 알고하지 않는 것 그것과 관련이있다. 네트워크 탭에서

ReferenceError: data is not defined 
    at Object.$scope.submitForm (http://0.0.0.0:3000/assets/controllers/DesignViewCtrl.js?body=1:203:18) 
    at http://0.0.0.0:3000/assets/lib/angular.min.js?body=1:1936:30 
    at http://0.0.0.0:3000/assets/lib/angular.min.js?body=1:4127:15 
    at Object.e.$eval (http://0.0.0.0:3000/assets/lib/angular.min.js?body=1:2432:24) 
    at Object.e.$apply (http://0.0.0.0:3000/assets/lib/angular.min.js?body=1:2439:40) 
    at HTMLFormElement.<anonymous> (http://0.0.0.0:3000/assets/lib/angular.min.js?body=1:4126:15) 
    at HTMLFormElement.jQuery.event.dispatch (http://0.0.0.0:3000/assets/jquery.js?body=1:2940:98) 
    at HTMLFormElement.elemData.handle (http://0.0.0.0:3000/assets/jquery.js?body=1:2750:123) 

반환 된 데이터는

{"data":[{"chrom":4.0,"chrom_start":55593607.0,"chrom_end":55593607.0}, {"chrom":"4","chrom_start":55593609.0,"chrom_end":55593617.0},{"chrom":"6","chrom_start":133105152.0,"chrom_end":133105152.0}]} 

또한 응답에 변화 시도, 그러나이 또한 작동하지 않았다.

}).success(resp)(function() { 
    $scope.selector.tabledata = resp.data; 
    $scope.uploaded = true; 
    }); 

답변

1

확실하지만 내가 본 것 success에 구조하지 보인다

.success(function(data, status, headers, config) { $scope.selector.tabledata = data; $scope.uploaded = true; });

같은
관련 문제