2014-07-17 6 views
0

기본 페이지가 있습니다. 범위에서 수동으로 json 데이터를 정의 할 수 있으며, 모든 것이 잘 작동합니다.

예 :

<!DOCTYPE html> 
<html ng-app="ordersApp"> 
<head> 

<scrip src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.15/angular.js"></scrip> 
</head> 
<body> 

<h1>Recent Orders</h1> 
<table ng-controller="orderCtrl"> 
<tr> 
<th>Order Date</th> 
<th>Stock Description</th> 
<th>Order #</th> 
<th>Order Value</th> 

</tr> 


     <tr ng-repeat="item in orders track by $index"> 
     <td>[[item.oh_statusdate]]</td> 
     <td>[[item.ol_stockdesc]]</td> 
     <td>[[item.oh_orderno]]</td> 
     <td>[[item.oh_ordervalue]]</td> 

    </tr> 

</table> 

<scrip> 

// register the app 
var ordersApp = angular.module('ordersApp', []); 
// alllow [[var]] instead of {{var}} for jinja2 
this.ordersApp.config(function($interpolateProvider) { 
      $interpolateProvider.startSymbol('[['); 
      $interpolateProvider.endSymbol(']]'); 
     }); 
// create a controller inside the app 
ordersApp.controller('orderCtrl', function ($scope) { 
    // assign the json data 
    $scope.orders = [ 
       {"ol_stockdesc": "EALANT", 
       "oh_statusdate": "2014-07-02", 
       "oh_custaccref": "416", 
       "oh_ordervalue": null, 
       "oh_orderno": 449605}, 

       {"ol_stockdesc": " BAG 25kg A", 
       "oh_statusdate": "2014-07-04", 
       "oh_custaccref": "416", 
       "oh_ordervalue": null, 
       "oh_orderno": 449824}, 

       {"ol_stockdesc": "BOTTLE B", 
       "oh_statusdate": "2014-07-04", 
       "oh_custaccref": "416", 
       "oh_ordervalue": null, 
       "oh_orderno": 449824}, 

       {"ol_stockdesc": "CREDIT CARD ADMIN & SURCHARGE", 
       "oh_statusdate": "2014-07-04", 
       "oh_custaccref": "416", 
       "oh_ordervalue": null, 
       "oh_orderno": 449824} 
       ]; 
}); 
</scrip> 

</body> 

</html> 

위의 작품 잘, 나는 일을하려고하지만 경우 다음

// register the app 
var ordersApp = angular.module('ordersApp', []); 
// alllow [[var]] instead of {{var}} for jinja2 
this.ordersApp.config(function($interpolateProvider) { 
      $interpolateProvider.startSymbol('[['); 
      $interpolateProvider.endSymbol(']]'); 
     }); 
ordersApp.controller("orderCtrl", function($scope, $http) { 
    $http.get('http://0.0.0.0:6543/orders.json?customer=416'). 
    success(function(data, status, headers, config) { 
     $scope.orders = data; 
    }). 
    error(function(data, status, headers, config) { 
     // log error 
    }); 
}); 

그것은 작동하지 않습니다 내가 개발 도구와 요청을 검사하고 볼 수있는 데이터 요청이 성공적으로 이루어지고 $ scope와 내 데이터가 검사되면 콘솔에서도 오류를 기록하지 않습니다. 누군가가 이것에 대해 약간의 빛을 비출 수 있다면 그것은 크게 감사 할 것입니다. 방화벽으로 인해 태그를 게시 할 수 없으므로 예제 코드는 "스크립트"대신 "스크립트"로 표시됩니다.

+1

json _exactly_가 동일한가요? –

+0

예, 정확하게 동일합니다. – crooksey

+0

''및 ''태그는 오타가 있습니까? –

답변

0

$scope 변경 사항을 $apply으로 묶으시겠습니까? 이처럼 :

$scope.$apply($scope.orders = data); 

이유는 당신의 Clojure에에 한번이 될 수는 $scope 범위는 같은 의미가 없습니다.

이 그것이 미래을 사용하고 요청 앤디 Gaskell의 주석 사항에 따라

+0

답장을 보내 주셔서 감사합니다. 다시 말하지만, 나의 데이터는 여전히 $ 범위 안에 있음을 보여줍니다. – crooksey

+0

Ok :(데이터가 $ scope에 있더라도 $ apply가 올바른 이벤트를 보내고 ng-repeat를 다시 작성해야합니다. –

+0

서버가 파이썬을 통해 생성 한 JSON의 약간의 차이가있을 수 있다고 생각합니다. 그냥 조사하는 것입니다. – crooksey

0

의 말에 잘 배열을 채 웁니다로 대신 $http$resource을 사용하는 일을 방지 할 수있는 방법, 나는 트리플 내 JSON을 확인 서버가 한 곳에서 여분의 따옴표와 백 슬래시를 추가하는 중이었기 때문에 신속하게이 코드를 수정 했으므로 이제는 기존 코드가 완벽하게 작동합니다.

관련 문제