小编use*_*041的帖子

angularjs ng-repeat with filter and track by $ index not working

我试图把一些视频,这个名称位于这个json文件,在div内,这是json文件:

{
    "videos": {
        "name": [
            "dfg.webm",
            "fdgh.mp4"
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

这是脚本:

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

    var videoUrl=function(name){
        alert("asd");
        return "./videos/"+name;
    };  
    app.filter('videoUrl',function(){alert("asd");return videoUrl;});

    var mainController=function($scope,$http){
       var videosSuccess=function(response){
           $scope.videosJSON=response.data;         
       };
       var videosError=function(response){};
       $http({
           method: 'GET',
           url: "http://192.168.1.66/videos.json",
       }).then(videosSuccess,videosError);
    };
    app.controller("mainController",["$scope","$http",mainController]);

}());
Run Code Online (Sandbox Code Playgroud)

这是html:

<html lang="es" ng-app="index">
    <head>
    ...
    </head>
    <body ng-controller="mainController">
        <div id="videosdiv">
            <video ng-repeat="video in videosJSON.videos.name | filter:videoUrl track by $index" preload="metadata" ng-src="{{video}}" type="video/webm">      
            </video>
        </div>

    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

问题是浏览器呈现这个:

<video data-ng-repeat="video in videosJSON.videos.name | filter:videoUrl track by $index" preload="metadata" ng-src="dfg.webm" type="video/webm" …
Run Code Online (Sandbox Code Playgroud)

arrays angularjs angularjs-ng-repeat angularjs-filter

3
推荐指数
1
解决办法
1万
查看次数