在View中遍历JSON

Iterate over JSON in View

本文关键字:JSON 遍历 View      更新时间:2023-09-26

我正在学习使用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>

大多数绑定使用$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,但来自用户的任何内容都应该被视为不安全的