小编jas*_*130的帖子

导出到 csv 时忽略 JSON 字符串中的逗号

我使用Filesaver.jsjson-export-excel.js将 json 文件导出到 csv 。当逗号分隔符在字符串中看到逗号时,会导致列移动。

笨蛋演示

如何忽略字符串中的逗号?

<button ng-json-export-excel data="data" report-fields="{name: 'Name', quote: 'Quote'}" filename ="'famousQuote'" separator="," class="purple_btn btn">Export to Excel</button>
Run Code Online (Sandbox Code Playgroud)

JS文件:

$scope.data = [
  {
    name: "Jane Austen",
    quote: "It isn\'t what we say or think that defines us, but what we do.",
  },
  {
    name: "Stephen King",
    quote: "Quiet people have the loudest minds.",
  },
]
Run Code Online (Sandbox Code Playgroud)

当前 CSV 输出(不需要):(注意:|标记 csv 文件中的列)

Name          Quote                                        
Jane Austen |  It isn't what we say …
Run Code Online (Sandbox Code Playgroud)

javascript json export-to-csv angularjs filesaver.js

6
推荐指数
1
解决办法
7552
查看次数

功能单元测试

我正在为函数 getNextPage() 编写单元测试。我设置了测试:expect(this.anotherService.resources).toEqual(3); 我收到错误:运行测试时预期未定义等于 3。我记录了 anotherService.resources,它在控制台中返回了 3。不知道为什么它不起作用。

测试

describe('Test for someController', function() {
  beforeEach(function() {
    module('someApp');
    return inject(function($injector) {
      var $controller;
      var $q = $injector.get('$q');

      this.rootScope = $injector.get('$rootScope');
      $controller = $injector.get('$controller');
      this.state = $injector.get('$state');
      this.stateParams = {
        id: 1,
      }
      this.location = $injector.get('$location')
      this.timeout = $injector.get('$timeout')
      this.upload = $injector.get('$upload')
      this.someService = {
        getItemList: function(res) {
          var deferred = $q.defer();
          deferred.resolve({
            data: {
              totalRows: 2,
              rows: 3,
            }
          });
          return deferred.promise;
        },
        pages: jasmine.createSpy(),

        memberIds: 1,
        currEng: []
      };
      this.anotherService = …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing function jasmine

2
推荐指数
1
解决办法
123
查看次数