【发布时间】:2017-02-14 14:43:54
【问题描述】:
我想知道有没有办法在嵌套的 ng-repeat 中添加动态生成的名称,例如:
<div ng-repeat="x in JSONfile">
<div ng-repeat="i in x.name">
<span><a ng-href="{{i.link}}">{{i.name}}</a></span>
</div>
</div>
JSONfile:返回一些名称,
x.name 是从提到的 JSONfile 动态生成的,它应该用作像“NAME”这样的纯文本,如果我添加 NAME 而不是 i.name,我会加载 json 文件,但我希望它自动加载,因为我不知道哪个名字会先出现。
i.name 返回:
n
a
m
e
不是应该的“NAME”..
所以,问题是,有没有办法告诉 Angular 我希望这个动态生成的值在我输入时被查看?
PS。
x.name 加载一个 JSON 文件,其中包含一些关于某个人的信息。
如果我输入 ng-repeat="i in Tom" 它将返回 json,但使用 x.name 它不起作用。
谢谢!
编辑(添加 json):
var brojVijesti = [ ];
$scope.JSONfile = brojVijesti;
// LNG Json
$http.get("/LEADERBOARDv2/jsons/LNG.php").then(function(response) {
var LNG = response.data.LNG;
$scope.LNG = LNG;
$scope.LNGbroj = LNG.length;
brojVijesti.push({"name":"LNG", "number":LNG.length});
});
// DT JSON
$http.get("/LEADERBOARDv2/jsons/DT.php").then(function (response) {
var DT = response.data.DT;
$scope.DT = DT;
$scope.DTbroj = DT.length;
brojVijesti.push({"name": "DT", "number": DT.length});
});
【问题讨论】:
-
什么是json样本格式?
-
您介意分享 JSON 吗?
-
你为什么不直接使用
x.name你为什么要循环名字? -
@manish :我需要从 $scope 获取 LNG 或 DT。 LNG 和 DT 以及许多其他的,都是动态生成的。
标签: javascript angularjs json ng-repeat