gpt4 book ai didi

java - angular - 从 java 捕获新行(\n)

转载 作者:行者123 更新时间:2023-11-30 08:36:17 26 4
gpt4 key购买 nike

我在 catching 或检测到 new line(\n) 从我的服务器端(java servlet)插入时遇到问题 Angular ng-repeat.

服务器端:

StringBuilder name = new StringBuilder();
name.append(getFirst(id)); //id - @param
name.append("\n"); //new line
name.append(getLast(id)); //id - @param

但在我的客户端,在我的 ng-repeat 中:

{{reporter.name}} //jhon doe而不是:

母鹿如果需要更多代码,我会发布。

最佳答案

您可以根据需要使用 css 样式:

white-space: pre|pre-line|pre-wrap;

pre - Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML
pre-line - Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks
pre-wrap Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example111-production</title>


<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-sanitize.js"></script>

<style>
table {
border-collapse: collapse;
}

table, td, th {
border: 1px solid black;
}
</style>


</head>
<body ng-app="sanitizeExample">
<script>
angular.module('sanitizeExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.friends = [
{name:'John\nDoe', age:25, gender:'boy'},
{name:'Jessie\nSimpson', age:30, gender:'girl'},
{name:'Johanna\nLN', age:28, gender:'girl'},
{name:'Joy\nLN', age:15, gender:'girl'},
{name:'Mary\nLN', age:28, gender:'girl'},
{name:'Peter\nLN', age:95, gender:'boy'},
{name:'Sebastian\nLN', age:50, gender:'boy'},
{name:'Erika\nLN', age:27, gender:'girl'},
{name:'Patrick\nLN', age:40, gender:'boy'},
{name:'Samantha\nLN', age:60, gender:'girl'}
];

}]);


</script>
<div ng-controller="ExampleController">
<table
class="table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Gender</th>

</tr>
</thead>
<tbody>
<tr data-ng-repeat="friend in friends">
<td style="white-space: pre;">{{friend.name}}</td>
<td>{{friend.age}}</td>
<td>{{friend.gender}}</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

关于java - angular - 从 java 捕获新行(\n),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37859686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com