使用中断Angularjs将数据导出为CSV

时间:2017-06-29 06:56:10

标签: angularjs csv newline line-breaks

以下是将数据放入CSV中的代码。我无法在每个用户之后放置换行符。

$scope.users = [ {"users": "Sample A", "last_login": "2013-10-10 10:10:10"},
                 {"users": "Sample B", "last_login": "2013-10-10 10:30:10"}


var iCtr;
var loginUsers = $scope.users;

  $scope.loginHeader = ["Name","Last Login"];

  $scope.csvData = [];

    if (iCtr == 0) {
      for (var iCounter in loginUsers) {
        $scope.loginHeader.push(loginUsers[iCounter].name);
      }
    }

    var objCSV = {};
    var iCntr=0;  
      for (var iCounter in loginUsers) {
          objCSV[iCntr] = [loginUsers[iCounter].first_name + " " + loginUsers[iCounter].last_name, loginUsers[iCounter].lastLogin];
        }
        iCntr++;
      }
    $scope.csvData.push(objCSV);

这是我想要的输出:

Name,Last login
Sample A,2013-10-10 10:10:10
Sample B,2013-10-10 10:30:10

这是我的输出。

Name,Last login
Sample A,2013-10-10 10:10:10, Sample B,2013-10-10 10:30:10

0 个答案:

没有答案