ng-repeat
을 사용하여 채울 테이블이 있습니다. 내 배열을 형식화하여 작동하도록하는 방법을 찾는 데 문제가 있습니다. 여기에 지금까지 무엇을 가지고 :AngularJS의 ng-repeat 지시어에 사용할 PHP 배열을 어떻게 포맷합니까?
PHP (customers.php) :
$customer_array = array();
$customer1 = array(
'customer_id' => '1',
'name' => 'John Doe',
'city' => 'New York'
);
$customer_array[] = $customer1;
$customer2 = array(
'customer_id' => '2',
'name' => 'Jane Doe',
'city' => 'Boston'
);
$customer_array[] = $customer2;
echo($customer_array);
AngularJS와 컨트롤러 (CustomersCtrl.js) :
$http({
url: 'customers.php',
method: "POST"
})
.success(function (data, status) {
$scope.customers = data;
})
.error(function (data, status) {
$scope.status = status;
});
HTML :
<table>
<tbody ng-controller="CustomersCtrl">
<tr ng-repeat="customer in customers">
<td>{{customer.customer_id}}</td>
<td>{{customer.name}}</td>
<td>{{customer.city}}</td>
</tr>
</tbody>
</table>
이것은 작동하지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까? 새로로드 된 HTML 템플릿이 컨트롤러에 바인딩되지 않기 때문에
$routeProvider.when('/customers.php', {
templateUrl: 'partials/customers.html',
controller: 'CustomersCtrl'
});
그것을인가 :
업데이트 : 아래의 코드를 사용하여 위의 HTML 코드를로드하고 있습니다 때문에이 경우 가 궁금하네요 ng-repeat
루프를 시도하기 전에?
나는로 json_encode를 추가 있지만 여전히 작동하지 않습니다. 나는이 기능을 "ul li"과 함께 많이 사용했기 때문에 이것이 왜 작동하지 않는 것인지 잘 모르겠습니다. –
각도가 가치가 있는지 궁금해지기 시작했습니다. 이것은 그렇게 간단한 일처럼 보입니다. 그러나 하루 종일 운 좋게 하루 종일 보냈습니다! 좌절을 넘어서. –
브라우저의 JavaScript 콘솔에 표시되는 내용은 무엇입니까? 'success' 함수 안에서'console.log ($ scope.customers)'를하면 어떻게 될까요? Google 크롬 관리자 (또는 유사한 도구)의 네트워크 탭이 서버에서 반환되는 이유는 무엇인가요?성공 함수가 호출되는 것입니까? 특정 문제에 대해 도움을 드릴 수는 있지만 화면에 실제 오류가 표시되지 않으면 "계속 작동하지 않음"으로 충분하지 않습니다. –