2017-02-18 169 views
-1
object(stdClass)#2 (1) { 
    ["CaseId"]=> 
    string(27) "SEAD-NLRC-NCR-11-00002-2016" 
} 

[ 
    { 
    "Case_ID": "2", 
    "Case_Status": "Withdrawn", 
    "Case_Reference_Number": "SEAD-NLRC-NCR-11-00002-2016", 
    "Case_Date_Filed": "November,24,Thursday,2016 1:30 PM", 
    "Requesting_Party_Full_Name": "Anak ng diyablo corporation", 
    "Requesting_Party_Age": "99", 
    "Requesting_Party_Gender": "", 
    "Requesting_Party_Address": "sa ilalim ng lupa siyempre", 
    "Requesting_Party_Full_Contact_Info": "09207819920", 
    "Requesting_Party_Date_Of_Employment": "30 November, 2016", 
    "Requesting_Party_Nature_Of_Work": "nag babantay ng mga maiinit na bato", 
    "Requesting_Party_Salary_Rate": "5000", 
    "Responding_Party_Full_Name": "angheles junkshop", 
    "Responding_Party_Nature_Of_Business": "Construction", 
    "Responding_Type_Of_Enterprise": "MICRO (1-9)", 
    "Responding_Party_Position": "mercenary naman", 
    "Responding_Party_HouseNo": "", 
    "Responding_Party_Street": "", 
    "Responding_Party_Barangay": "", 
    "Responding_Party_ZipCode": "", 
    "Responding_Party_City": "", 
    "Responding_Party_Contact_Details": "miguelita", 
    "Responding_Party_Full_Contact_Info": "[email protected]", 
    "Case_Holder": "DESK-75034-2016", 
    "Notice_Of_Conference": "None", 
    "Remarks": "Not Set", 
    "Remarks_Date": "Not Set", 
    "Remarks_Time": "Not Set", 
    "Joint_Conference_Holder": "DESK-00060-2016", 
    "Lawyer_Holder": "DESK-10101-2017" 
    } 
] 

如何以這種格式獲取對象內的數據。 我正在使用AngularJS,我想用$http.post致電ng-repeat如何從對象中獲取數據

回答

0

試試這個

<!DOCTYPE html> 
 
<html ng-app="UserValue"> 
 
<head> 
 
\t <script type="text/javascript" src="https://code.angularjs.org/1.5.5/angular.min.js"></script> 
 
\t <script type="text/javascript"> 
 
\t \t var app = angular.module('UserValue', []); 
 
\t \t app.controller('UserFirstValue', function ($scope) { 
 
\t \t \t $scope.myArray = [{ 
 
\t \t \t \t "Case_ID": "2", 
 
\t \t \t \t "Case_Status": "Withdrawn", 
 
\t \t \t \t "Case_Reference_Number": "SEAD-NLRC-NCR-11-00002-2016", 
 
\t \t \t \t "Case_Date_Filed": "November,24,Thursday,2016 1:30 PM", 
 
\t \t \t \t "Requesting_Party_Full_Name": "Anak ng diyablo corporation", 
 
\t \t \t \t "Requesting_Party_Age": "99", 
 
\t \t \t \t "Requesting_Party_Gender": "", 
 
\t \t \t \t "Requesting_Party_Address": "sa ilalim ng lupa siyempre", 
 
\t \t \t \t "Requesting_Party_Full_Contact_Info": "09207819920", 
 
\t \t \t \t "Requesting_Party_Date_Of_Employment": "30 November, 2016", 
 
\t \t \t \t "Requesting_Party_Nature_Of_Work": "nag babantay ng mga maiinit na bato", 
 
\t \t \t \t "Requesting_Party_Salary_Rate": "5000", 
 
\t \t \t \t "Responding_Party_Full_Name": "angheles junkshop", 
 
\t \t \t \t "Responding_Party_Nature_Of_Business": "Construction", 
 
\t \t \t \t "Responding_Type_Of_Enterprise": "MICRO (1-9)", 
 
\t \t \t \t "Responding_Party_Position": "mercenary naman", 
 
\t \t \t \t "Responding_Party_HouseNo": "", 
 
\t \t \t \t "Responding_Party_Street": "", 
 
\t \t \t \t "Responding_Party_Barangay": "", 
 
\t \t \t \t "Responding_Party_ZipCode": "", 
 
\t \t \t \t "Responding_Party_City": "", 
 
\t \t \t \t "Responding_Party_Contact_Details": "miguelita", 
 
\t \t \t \t "Responding_Party_Full_Contact_Info": "[email protected]", 
 
\t \t \t \t "Case_Holder": "DESK-75034-2016", 
 
\t \t \t \t "Notice_Of_Conference": "None", 
 
\t \t \t \t "Remarks": "Not Set", 
 
\t \t \t \t "Remarks_Date": "Not Set", 
 
\t \t \t \t "Remarks_Time": "Not Set", 
 
\t \t \t \t "Joint_Conference_Holder": "DESK-00060-2016", 
 
\t \t \t \t "Lawyer_Holder": "DESK-10101-2017" 
 
\t \t \t }] 
 

 
\t \t }); 
 
\t </script> 
 
</head> 
 
<body ng-controller="UserFirstValue"> 
 
<div ng-repeat="data in myArray"> 
 
    <div>Case_ID: {{data.Case_ID}}</div> 
 
    <div>Responding_Party_Position: {{data.Responding_Party_Position}}</div> 
 
    <div>Lawyer_Holder: {{data.Lawyer_Holder}}</div> 
 
</div> 
 
</body> 
 
</html>

0

使用JavaScript

DEMO

var jsonObj = [ 
 
    { 
 
    "Case_ID": "2", 
 
    "Case_Status": "Withdrawn", 
 
    "Case_Reference_Number": "SEAD-NLRC-NCR-11-00002-2016", 
 
    "Case_Date_Filed": "November,24,Thursday,2016 1:30 PM", 
 
    "Requesting_Party_Full_Name": "Anak ng diyablo corporation", 
 
    "Requesting_Party_Age": "99", 
 
    "Requesting_Party_Gender": "", 
 
    "Requesting_Party_Address": "sa ilalim ng lupa siyempre", 
 
    "Requesting_Party_Full_Contact_Info": "09207819920", 
 
    "Requesting_Party_Date_Of_Employment": "30 November, 2016", 
 
    "Requesting_Party_Nature_Of_Work": "nag babantay ng mga maiinit na bato", 
 
    "Requesting_Party_Salary_Rate": "5000", 
 
    "Responding_Party_Full_Name": "angheles junkshop", 
 
    "Responding_Party_Nature_Of_Business": "Construction", 
 
    "Responding_Type_Of_Enterprise": "MICRO (1-9)", 
 
    "Responding_Party_Position": "mercenary naman", 
 
    "Responding_Party_HouseNo": "", 
 
    "Responding_Party_Street": "", 
 
    "Responding_Party_Barangay": "", 
 
    "Responding_Party_ZipCode": "", 
 
    "Responding_Party_City": "", 
 
    "Responding_Party_Contact_Details": "miguelita", 
 
    "Responding_Party_Full_Contact_Info": "[email protected]", 
 
    "Case_Holder": "DESK-75034-2016", 
 
    "Notice_Of_Conference": "None", 
 
    "Remarks": "Not Set", 
 
    "Remarks_Date": "Not Set", 
 
    "Remarks_Time": "Not Set", 
 
    "Joint_Conference_Holder": "DESK-00060-2016", 
 
    "Lawyer_Holder": "DESK-10101-2017" 
 
    } 
 
]; 
 

 
var res = jsonObj.map(function(item) { 
 
return item.Case_ID; 
 
}); 
 

 
console.log(res);

DEMO

var jsonObj = [ 
 
    { 
 
    "Case_ID": "2", 
 
    "Case_Status": "Withdrawn", 
 
    "Case_Reference_Number": "SEAD-NLRC-NCR-11-00002-2016", 
 
    "Case_Date_Filed": "November,24,Thursday,2016 1:30 PM", 
 
    "Requesting_Party_Full_Name": "Anak ng diyablo corporation", 
 
    "Requesting_Party_Age": "99", 
 
    "Requesting_Party_Gender": "", 
 
    "Requesting_Party_Address": "sa ilalim ng lupa siyempre", 
 
    "Requesting_Party_Full_Contact_Info": "09207819920", 
 
    "Requesting_Party_Date_Of_Employment": "30 November, 2016", 
 
    "Requesting_Party_Nature_Of_Work": "nag babantay ng mga maiinit na bato", 
 
    "Requesting_Party_Salary_Rate": "5000", 
 
    "Responding_Party_Full_Name": "angheles junkshop", 
 
    "Responding_Party_Nature_Of_Business": "Construction", 
 
    "Responding_Type_Of_Enterprise": "MICRO (1-9)", 
 
    "Responding_Party_Position": "mercenary naman", 
 
    "Responding_Party_HouseNo": "", 
 
    "Responding_Party_Street": "", 
 
    "Responding_Party_Barangay": "", 
 
    "Responding_Party_ZipCode": "", 
 
    "Responding_Party_City": "", 
 
    "Responding_Party_Contact_Details": "miguelita", 
 
    "Responding_Party_Full_Contact_Info": "[email protected]", 
 
    "Case_Holder": "DESK-75034-2016", 
 
    "Notice_Of_Conference": "None", 
 
    "Remarks": "Not Set", 
 
    "Remarks_Date": "Not Set", 
 
    "Remarks_Time": "Not Set", 
 
    "Joint_Conference_Holder": "DESK-00060-2016", 
 
    "Lawyer_Holder": "DESK-10101-2017" 
 
    } 
 
]; 
 

 
for(var i in jsonObj) { 
 
console.log(jsonObj[i].Case_ID); 
 
}

使用AngularJS

  • 使用ng-repeat

var myApp = angular.module('myApp', []); 
 

 
myApp.controller('MyCtrl',function($scope) { 
 

 
$scope.jsonObj = [ 
 
    { 
 
    "Case_ID": "2", 
 
    "Case_Status": "Withdrawn", 
 
    "Case_Reference_Number": "SEAD-NLRC-NCR-11-00002-2016", 
 
    "Case_Date_Filed": "November,24,Thursday,2016 1:30 PM", 
 
    "Requesting_Party_Full_Name": "Anak ng diyablo corporation", 
 
    "Requesting_Party_Age": "99", 
 
    "Requesting_Party_Gender": "", 
 
    "Requesting_Party_Address": "sa ilalim ng lupa siyempre", 
 
    "Requesting_Party_Full_Contact_Info": "09207819920", 
 
    "Requesting_Party_Date_Of_Employment": "30 November, 2016", 
 
    "Requesting_Party_Nature_Of_Work": "nag babantay ng mga maiinit na bato", 
 
    "Requesting_Party_Salary_Rate": "5000", 
 
    "Responding_Party_Full_Name": "angheles junkshop", 
 
    "Responding_Party_Nature_Of_Business": "Construction", 
 
    "Responding_Type_Of_Enterprise": "MICRO (1-9)", 
 
    "Responding_Party_Position": "mercenary naman", 
 
    "Responding_Party_HouseNo": "", 
 
    "Responding_Party_Street": "", 
 
    "Responding_Party_Barangay": "", 
 
    "Responding_Party_ZipCode": "", 
 
    "Responding_Party_City": "", 
 
    "Responding_Party_Contact_Details": "miguelita", 
 
    "Responding_Party_Full_Contact_Info": "[email protected]", 
 
    "Case_Holder": "DESK-75034-2016", 
 
    "Notice_Of_Conference": "None", 
 
    "Remarks": "Not Set", 
 
    "Remarks_Date": "Not Set", 
 
    "Remarks_Time": "Not Set", 
 
    "Joint_Conference_Holder": "DESK-00060-2016", 
 
    "Lawyer_Holder": "DESK-10101-2017" 
 
    } 
 
]; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="myApp" ng-controller="MyCtrl"> 
 
    <div ng-repeat="case in jsonObj"> 
 
    Case ID : {{case.Case_ID}} 
 
    </div> 
 
</div>

注: AngularJS d oes不允許在ng-repeat指令中有重複。這意味着如果您正在嘗試執行以下操作,則會出現錯誤。

<div ng-repeat="names in [alpha,alpha]">

刪除這個問題,你必須使用track by $indexng-repeat指令。

<div ng-repeat="names in [alpha,alpha] track by $index">