拆分td中的文本并以换行符

时间:2017-01-20 20:31:17

标签: javascript angularjs text split

示例==> plunkr

我做了什么:从上面开始,我在表格中传递了以下文字 - td(日志)。

需要什么:需要将文本分割为 \“。并显示在新行上。

  

“\”Lorem ipsum dolor坐下来,精神恍惚。 Animi,   必需品。\“,”Lorem ipsum dolor坐下来,念念   adipisicing elit。 Animi,必需品。] \“,”Lorem ipsum dolor坐   amet,consectetur adipisicing elit。 Animi,必需品。\“,”Lorem   ipsum dolor坐着。 \ “”

scripts.js中

var app = angular.module("app", []);

app.controller('splitText', function($scope) {
  $scope.text = "text";
  $scope.log = "\"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, necessitatibus.\", \" Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, necessitatibus.]  \",\"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, necessitatibus.\", \"Lorem ipsum dolor sit amet.  \",";
  $scope.logs = $scope.log.replace(/,/g, '\n');
});

的index.html

<!DOCTYPE html>
<html>

  <head>
    <link data-require="bootstrap-css@*" data-semver="4.0.0-alpha.4" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/css/bootstrap.min.css" />
    <script data-require="angularjs@1.5.7" data-semver="1.5.7" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-app="app" ng-controller="splitText" class="container">
    <h1>Hello Plunker!</h1>
    <p class="">{{text}}</p>
    <table class="table table-bordered">
      <thead>
        <th>#</th>
        <th>Name</th>
        <th>Logs</th>
      </thead>
      <tbody>
        <td>1</td>
        <td>Log</td>
        <td>{{logs}}</td>
      </tbody>
    </table>
  </body>

</html>

0 个答案:

没有答案