Ich versuche, spezifische JSON-Daten von einem AngularJS-Filter aufzurufen. Grundsätzlich möchte ich, dass ein Benutzer auf eine der otpions in der Abfrage-/Suchleiste klickt und zugehörige JSON-Daten in einem anderen div anzeigt. Mit ng-click und ng-show kann ich das div anzeigen, aber ich kann die JSON-Daten nicht anzeigen.Ng-click und ng-show zeigen keine JSON-Daten an
Hier ist mein Code:
var app = angular.module('myApp', []);
app.controller("MyCtrl", function($scope) {
\t $scope.myvalue = false;
\t $scope.showAlert = function(){
\t $scope.myvalue = true;
\t };
\t $scope.schools = [
{
"districtcleaned": "Test ISD",
"campus": "Test school",
"gradesimplified": "C",
"level": "Elementary",
}
]
})
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- begin snippet: js hide: false console: true babel: false -->
<head>
\t <!---AngularJS--->
\t <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="MyCtrl">
\t \t \t <section class="form">
\t \t \t \t <form class="form-inline">
\t \t \t \t \t <input class="input-special" ng-model="query" type="text" placeholder="Search school rankings" autofocus>
\t \t \t \t </form>
\t \t \t \t <ul ng-show="query" class="ng-hide" ng-repeat="school in schools | filter:query | orderBy: 'name' | limitTo: 15">
\t \t \t \t \t <li ng-show="school" class="result">
\t \t \t \t \t \t <span class="category"><a ng-click="showAlert()">{{school.campus}}</a></span>
\t \t \t \t \t \t <span class="category"><i class="fa fa-pencil" aria-hidden="true"></i> {{school.level}}</span>
\t \t \t \t \t \t <span class="category">District: {{school.districtcleaned}}</span>
\t \t \t \t \t \t <span class="category">Grade: {{school.gradesimplified}}</span>
\t \t \t \t \t </li>
\t \t \t \t </ul>
\t \t \t \t <div class="school-details ng-hide" ng-show="myvalue">
\t \t \t \t \t <p>School: {{school.campus}}</p>
\t \t \t \t \t <p>District: {{school.districtcleaned}}</p>
\t \t \t \t </div>
\t \t \t </section>
\t \t </div>
</body>
Ich bin neu in AngularJS und JSON so dass jeder und alle Hilfe geschätzt. Vielen Dank!
Sie müssen es konvertieren. Versuchen Sie: Lassen Sie myJson = JSON.stringify (URJSON, null, 2) und dann "myJson" anzeigen – archae0pteryx