显示数组结果在marquee标签中,如新闻自动收报机

时间:2017-01-28 15:43:18

标签: javascript angularjs arrays

我正在尝试在新闻标签中显示我的ajax查询结果。 不幸的是,我无法在数组中显示内容。

JavaScript代码:

                success: function (data) {
                var NewsList= [];
                  for (var i = 0 ; i< data.query.table.length; i++) {
                       NewsList[i] = data.query.table[i];

                    };
                      $scope.news = NewsList;

         },

Html代码:

<div ng-controller ="newsController"><!-- ng-controller ="newsController" -->
    <marquee ng-repeat="new in news">{{new}}</marquee>

Chrome控制台日志中的输出:

[Array[1],Array[1],Array[1],.....]

数组内部的输出类似于数组[391] - &gt;数组[0-99] - &gt; 0:数组[1] - &gt; 0:&#34; hellowolrd&#34;。等等。

可能我必须遍历数组,但不幸的是我无法这样做。我正在使用ng - 重复angularjs。团队可以帮助我进行上述查询。 谢谢。

Json导致浏览器控制台

{"query":{"resultCode":0,"columns":["tnps_global_rating_reason_comment"],"table":[[""],["Im using a vodafone since 2010 to 2014 and from july 2016 up to now"],["Abhi bohot jaldi hai"],["سرعه الخدمه وجودتها"],["0"],[""],["خدمه عملاء جيده جدا وتم حل مشكلتي"],["2"]]}}

1 个答案:

答案 0 :(得分:0)

你可以这么做,

  <marquee ng-repeat="eachnew in news.query.table">{{eachnew}}</marquee> 

<强>样本

&#13;
&#13;
var app = angular.module('todoApp', []);
app.controller("newsController", ["$scope",
  function($scope) {
    $scope.news  = 
      {"query":{"resultCode":0,"columns":["tnps_global_rating_reason_comment"],"table":[[""],["Im using a vodafone since 2010 to 2014 and from july 2016 up to now"],["Abhi bohot jaldi hai"],["سرعه الخدمه وجودتها"],["0"],[""],["خدمه عملاء جيده جدا وتم حل مشكلتي"],["2"]]}};
  
 } 
]);
&#13;
<!DOCTYPE html>
<html ng-app="todoApp">

<head>
  <title>Sample</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
</head>
<body ng-controller="newsController">          
    <marquee ng-repeat="eachnew in news.query.table">{{eachnew}}</marquee>  
</body>
</html>
&#13;
&#13;
&#13;