angular.js - Problem with angualr's json acquisition.
ringa_lee
ringa_lee 2017-05-16 13:18:29
0
2
809

There are multiple a tags (a tag 1, a tag 2, a tag 3), and each button corresponds to different JSON data (JSON1, JSON2, JSON3). Please tell me how to set up when I click on the first a tag to load the corresponding JSON data?

Use ng-repeat to loop through multiple a tags.

 

{{data.title}}

{{data.dec}}

Then jump to the question target page. It is also looped out using ng-repeat. I just want to jump here on the previous page to get different json content.

{{data.title}}

Corresponding JSON file.

"JSON0":[{ "image":["img/001.jpg","img/002.jpg","img/026.jpg","img/014.jpg"], "title":"1234" }], "JSON1":[{ "image":["img/019.jpg","img/013.jpg"], "title":"4567" }}], "JSON2":[{ "image":["img/029.jpg","img/014.jpg"], "title":"78910" }]

Get JSON settings.

app.controller("content",function($scope,$http){ $scope.$watch("viewContentLoaded",function(){ $http({ method:"GET", url:"./zt.json" }).then(function(response){ //var test1 = response.data.zt.JSON0; //$scope.test = test1; $scope.topBanner = function($event,$index){ var test1 = "response.data.zt.ztTopbanner"+$index; $scioe.test = test1; } })

At first, I wanted to dynamically change the path to obtain JSON. Who knew an error was reported. . Probably because dynamic modification is not allowed or something? Only specified values? ? I don’t quite understand either. So find the solution! Newbies are stuck here! I've been looking for a long time but can't find a way!
Please give me some advice! Trouble!

ringa_lee
ringa_lee

ringa_lee

reply all (2)
淡淡烟草味

AngularJS does not allow duplicates in a ng-repeat directive. This means if you are trying to do the following, you will get an error.

However, changing the above code slightly to define an index to determine uniqueness as below will get it working again.

// This will work 

    曾经蜡笔没有小新

    @xsf_1991 Hello, one more question for you. Because my JSON objects are aa1, aa2, aa3, aa4, named in order. I just want to click to get the $index index, and add $index to the end of the JSON path. The purpose is to realize that when I click the first one, if the $index is 1, I will input aa1, and if it is 2, I will output aa2. But I wrote it incorrectly, that is, it becomes a string display, just like the second line in the picture. The first line is the correct display content I added myself.
    How do I write it to get the JSON path correctly?

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!