`
oywl2008
  • 浏览: 1003658 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Angularjs JS Parse JSON

 
阅读更多
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<script>
var app = angular.module("myShoppingList", []);



app.controller("myCtrl", function($scope) {

var arr=[[{"id":1,"orderName":"Order1470534767695","checkOut":false},{"id":1,"p":{"productId":1,"name":"QQ","price":11.0},"quantity":1,"orderPrice":11.0,"orderTime":1470534767883},{"productId":1,"name":"QQ","price":11.0}],[{"id":1,"orderName":"Order1470534767695","checkOut":false},{"id":2,"p":{"productId":2,"name":"RR","price":22.0},"quantity":1,"orderPrice":22.0,"orderTime":1470534767886},{"productId":2,"name":"RR","price":22.0}],[{"id":2,"orderName":"Order1470534771006","checkOut":false},{"id":3,"p":{"productId":3,"name":"TTT","price":33.0},"quantity":1,"orderPrice":33.0,"orderTime":1470534771028},{"productId":3,"name":"TTT","price":33.0}]];

//alert(arr.length);

//    alert(arr[0][0].id);
// alert(arr[1][0].id);
//alert(arr[2][0].id);

for(var i=0;i<arr.length;i++){
if(arr[i][0].id==1){
//alert(arr[i][0].orderPrice);
//alert(arr[i][1].p.name);
//alert(arr[i][0].id);
//alert(arr[i][1].quantity);
//alert(arr[i][1].p.name);
alert(arr[i][1].orderPrice);
}
}


    $scope.products = ["Milk", "Bread", "Cheese"];
    $scope.addItem = function () {
        $scope.products.push($scope.addMe);
    }
    $scope.removeItem = function (x) {
        $scope.products.splice(x, 1);
    }
});
</script>

<div ng-app="myShoppingList" ng-controller="myCtrl">
  <ul>
    <li ng-repeat="x in products">{{x}}<span ng-click="removeItem($index)">×</span></li>
  </ul>
  <input ng-model="addMe">
  <button ng-click="addItem()">Add</button>
</div>

<p>Click the little x to remove an item from the shopping list.</p>

</body>
</html>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics