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.
<a class="itemx" id="{{data.id}}" ng-repeat="data in toploops" ui-sref="{{data.sref}}" ng-click="topBanner($event,$index)">
<p class="image"><img ng-src="{{data.image}}"/></p>
<h4>{{data.title}}</h4>
<p>{{data.dec}}</p>
</a>
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.
<p class="card" ng-repeat="data in test">
<p class="item item-text-wrap">
{{data.title}}
</p>
<p class="item-image">
<img ng-repeat="x in data.image" ng-src="{{x}}"/>
</p>
</p>
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!
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.
@xsf_1991 你好,再问多你一个问题。因为我的JSON对象是aa1,aa2,aa3,aa4,这样按顺序命名的。我就想点击获取$index索引,往JSON路径后面加$index,目的是想实现我点击第一个的时候$index为1,就输入aa1,为2就输出aa2。但是我这样写不对,就是变成字符串显示,就像如图第二行,第一行是我自己加上去的正确显示内容。
请问要怎么写才能正确获取到JSON的路径呢?