Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从php获取数组时重复ng_Php_Json_Angularjs_Ng Repeat - Fatal编程技术网

从php获取数组时重复ng

从php获取数组时重复ng,php,json,angularjs,ng-repeat,Php,Json,Angularjs,Ng Repeat,好的,这看起来很简单,但显然我遗漏了一些东西,我已经放弃了理解什么,我的代码是这样的: 在我的php端,我从MySql数据库读取信息,它返回一个json编码的对象,如下所示: $rows = array(); while($row = mysqli_fetch_assoc($result)) { $rows[]=$row; } echo json_encode($rows); 在我的javascript方面,我尝

好的,这看起来很简单,但显然我遗漏了一些东西,我已经放弃了理解什么,我的代码是这样的:

在我的php端,我从MySql数据库读取信息,它返回一个json编码的对象,如下所示:

$rows = array();
        while($row = mysqli_fetch_assoc($result)) {
            $rows[]=$row;
        }    

        echo json_encode($rows);
在我的javascript方面,我尝试将这个数组的内容加载到我在一个控制器的作用域中创建的数组中(我有2个)

!!当检查控制台时,信息显示得非常完美,我得到了一个50个元素的数组,所有信息都在那里,正如图中所示->

我尝试使用以下html将所有数据放入一个表中

 <div id="quicksearchresults" ng-controller="EditableRowCtrl" data-ng-init="populate()">
    <div id='searchResults'>
        <table id='resultstable'>
            <thead>
               <tr style='background-color:#333333; color:whitesmoke;' class='headers'>
                      <th style='white-space: nowrap;' class='sort' data-sort='OIDid'>OID#</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='priority'>Priority</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='topic'>Topic</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='category'>Category</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='task'>Task</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='added'>Added</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='target'>Target</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='owner'>Owner</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='remarks'>Remarks</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='status'>Status</th>
               </tr> 
            </thead>
            <tbody class='list'>
                <tr ng-repeat='task in CurrentOIDs'>
                    <td class='OIDid'>{{ task.OIDid }}</td>
                    <td class='priority'>{{ task.Priority }}</td>
                    <td class='topic'>{{ task.Topic }}</td>
                    <td class='category'>{{ task.Category }}</td>
                    <td class='task'>{{ task.Task }}</td>      
                    <td class='added'>{{ task.Added }}</td>
                    <td class='target'>{{ task.Target }}</td>
                    <td class='owner'>{{ task.Owner }}</td>
                    <td class='remarks'>{{ task.Remarks }}</td>
                    <td class='status' style='font-size:150%; font-weight:bold;'>{{ task.Status }}%</td>
                </tr>
            </tbody>
        </table> 
    </div>
</div> 

老年人#
优先
话题
类别
任务
补充
目标
所有者
评论
地位
{{task.OIDid}
{{task.Priority}}
{{task.Topic}
{{task.Category}
{{task.task}
{{task.Added}
{{task.Target}
{{task.Owner}
{{任务.备注}
{{task.Status}}}%
现在我知道,当我在javascript中手动为数组提供相同的精确值,而不是从数据库中读取它们时,这是可行的。我注意到的一个区别是,每个对象都添加了一个字段$$hashkey,但据我所知,这是由于ng重复而添加的


我对angular的知识仍然是基础的,我不知道为什么这不起作用,并且已经没有东西可以在google上搜索了。非常感谢您的任何帮助。多谢各位

您可以粘贴完整的控制器代码吗?您使用jQuery进行AJAX调用,其成功回调发生在Angular的摘要循环之外。使用
$scope.$apply()
,或者(最好)使用
$http
来进行AJAX调用。好吧,非常讽刺的是,在发布这个问题几秒钟后,我尝试了$scope.$apply(),但它成功了,我不完全理解发生了什么,您能解释一下我为什么需要这个命令吗?感谢$http是特定于角度的并返回承诺,jQuery的AJAX调用在angularJS中不是“内置的”。如果AJAX调用返回,angularJS没有意识到您更改了数据,如果您使用$http,angularJS知道有事情正在进行,并对您的数据进行脏检查并绑定它们。进一步的信息:好的,所以我尝试使用$http实现它,我得到了:$http.get('getOidJSON.php',{criteria:'',归档:'NO'})。成功(函数(phpmarkup){$scope.CurrentOIDs=phpmarkup;console.log($scope.CurrentOIDs);}); 不过,这并不奇怪,它不起作用,这次是php方面的错误,数据似乎没有到达那里,有什么建议吗?
 <div id="quicksearchresults" ng-controller="EditableRowCtrl" data-ng-init="populate()">
    <div id='searchResults'>
        <table id='resultstable'>
            <thead>
               <tr style='background-color:#333333; color:whitesmoke;' class='headers'>
                      <th style='white-space: nowrap;' class='sort' data-sort='OIDid'>OID#</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='priority'>Priority</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='topic'>Topic</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='category'>Category</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='task'>Task</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='added'>Added</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='target'>Target</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='owner'>Owner</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='remarks'>Remarks</th>
                      <th style='white-space: nowrap;' class='sort' data-sort='status'>Status</th>
               </tr> 
            </thead>
            <tbody class='list'>
                <tr ng-repeat='task in CurrentOIDs'>
                    <td class='OIDid'>{{ task.OIDid }}</td>
                    <td class='priority'>{{ task.Priority }}</td>
                    <td class='topic'>{{ task.Topic }}</td>
                    <td class='category'>{{ task.Category }}</td>
                    <td class='task'>{{ task.Task }}</td>      
                    <td class='added'>{{ task.Added }}</td>
                    <td class='target'>{{ task.Target }}</td>
                    <td class='owner'>{{ task.Owner }}</td>
                    <td class='remarks'>{{ task.Remarks }}</td>
                    <td class='status' style='font-size:150%; font-weight:bold;'>{{ task.Status }}%</td>
                </tr>
            </tbody>
        </table> 
    </div>
</div>