douhuijun3776 2017-02-14 05:24
浏览 36

当列出3时,ANGULARJS结果消失

My query search all the dishes that the restaurant has on it's database.

<?php
include('base.php');
$data = array();
$result = mysql_query("SELECT nombre FROM platos WHERE tipo = 'principal'",$connect);
if(mysql_num_rows($result) > 0){
    while($row = mysql_fetch_assoc($result)){
        $data[] = $row;
    }
} else {
    echo "0 results";
};
echo json_encode($data);
mysql_close($connect);
?>

so then I invoke it on the angular code:

$http({
      method: 'GET',
      url: '../../php/getDishesPrincipal.php'
    }).then(function successCallback(response) {
        $scope.principals = response.data;
    }, function errorCallback(response) {
        $scope.principals = 'No Response';
    });

well, finally i print it on my html code:

<div id="agregarpedido_table_item" ng-repeat="principal in principals">
   <p id="agregarpedido_table_item_p">{{principal.nombre}}</p>
   <div id="agregarpedido_table_item_command">
     <p>{{principal.cant}}</p>
     <div class="selectors">
       <input type="button" value="+" ng-click="principal.cant = principal.cant + 1">
       <input type="button" value="-" ng-click="principal.cant = principal.cant - 1">
     </div>
   </div>

The issue is that when in my database theres more than 2 results that matches tipo: principal, the html disappears and it doesn`t show anything. Worst, the console doesn't throw any error about it as if it is normal. Any ideas?

  • 写回答

2条回答 默认 最新

  • dpfwhb7470 2017-02-14 06:07
    关注

    Because you are only getting back an array of names due to your SQL query, angular may be throwing a no-dupes error inside the ng-repeat.

    Try formatting your ng-repeat like this: ng-repeat="principal in principals track by $index"

    you may have 2 or more non-unique names for your principals, so angular throws a no dupe error. For reference, using the track by $index method can help improve render/binding performance in loops.

    here's a jsbin https://jsbin.com/noxawusoqe/2/edit?html,js,console,output

    Hope that works

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line