【发布时间】:2016-07-03 00:32:48
【问题描述】:
下面的代码使用 Javascript 和 PHP,但是当它运行时,我希望每个回显都在单独的行上。我尝试过使用 \n 和
和其他方法,但它们都对文本没有任何影响。谁能帮帮我?
function MyCtrl($scope) {
$scope.environment_service_packages =
[
{name: 'obj1', info: {text: '<?php echo "hello" . "\n" . "<br>" . "world"; ?>', show: true}},
{name: 'obj2', info: {text: 'some extra info for obj2', show: false}},
];
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app>
<table ng-controller="MyCtrl" class="table table-hover table-striped">
<tr class="info">
<td>...</td>
</tr>
<tbody ng-repeat="x in environment_service_packages">
<tr ng-click="x.info.show = !x.info.show">
<td> {{ x.name }}
</tr>
<tr ng-show="x.info.show">
<td>
{{ x.info.text }}
</td>
</tr>
</tbody>
</table>
</body>
编辑:由于某种原因,这个 sn-p 不能解释 php。
【问题讨论】:
-
我无法运行您的代码——它充满了未定义的变量。请查看此页面 -- minimal reproducible example -- 并给我们一个示例,该示例仅包含您希望我们解决的问题。
-
@TopologicalSort 好的,我已经更新了问题。
-
您的
<br>在这种情况下应该可以工作。您可以通过在 html 中手动编写内容来做一个小证明。为什么(有什么效果)你说他们没有工作?它们是否呈现为文本?如果是这样,可能是您的框架或引擎将其转义以输出文本表单。还是CSS的东西?没有一个最小的完整示例很难说。但是, td 中的 br 标记确实会产生换行符:) -
试试
<td ng-bind-html="x.info.text"></td>BTW - angularjs 的整个想法不是在客户端注入 PHP ...... -
@AlonEitan 没关系。我应该把那个代码放在哪里?
标签: javascript php newline