gpt4 book ai didi

javascript - 在 View 中迭代 JSON

转载 作者:行者123 更新时间:2023-12-02 16:24:37 26 4
gpt4 key购买 nike

我正在学习使用 MEAN 全栈,但遇到了一个无法找到解决方案的问题。

使用 ng-repeat 迭代 JSON 对象效果非常好,但在第三列中使用 x.url 变量根本不起作用。 URL 正确打印在第二列中。

如何在 iframe 中引用 x.url 变量?

谢谢。

<div class="jumbotron text-center">
<table class='table table-bordered'>
<caption>LIST OF ALL SONGS</caption>
<thead>{{ tagline }}</thead>
<tr ng-repeat="x in songs">
<td>{{x.name}}</td>
<td>{{x.url}}</td>
<td><iframe width="560" height="315" src={{x.url}} frameborder="0" allowfullscreen></iframe></td>
</tr>
</table>
</div>

最佳答案

大多数绑定(bind)使用 $sce 来清理元素并保护您免受潜在不安全内容的影响,如果您信任该 URL,则可以使用 $sce 来明确信任它

http://plnkr.co/edit/hJw5JWsteFBfiHH5d3QS

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

app.controller('MainCtrl', function($scope, $sce) {
$scope.tagline = "test"
$scope.songs = [{url: $sce.trustAsResourceUrl('http://angularjs.org'), name: 'test'}];
});

如果您信任内容,您也可以完全禁用 $sce,但来自用户的任何内容都应被视为不安全

关于javascript - 在 View 中迭代 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28794715/

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