gpt4 book ai didi

javascript - 在angularjs中的另一个数组中调用json数组

转载 作者:行者123 更新时间:2023-12-03 12:12:43 24 4
gpt4 key购买 nike

我是 Angular 和 json 的新手,所以如果有人可以帮助我。

我有 json 数组,其中有用户和用户购买商品的卖家名称。

Json:

[
{
"name":"Kakaro",
"sallers":[
{"sellername":"Naruto","payment":"250","date":"07\/07\/2014","receipt":"popup"},
{"sellername":"Sasuka","payment":"502","date":"08\/07\/2014","receipt":"popup"}
]
},
{
"name":"Collin Ferall",
"sallers":[
{"sellername":"Jonny deep","payment":"250","date":"07\/07\/2014","receipt":"popup"},
{"sellername":"Brad Pitt","payment":"502","date":"08\/07\/2014","receipt":"popup"}
]
}
]

我想做的事情:当我们选择用户时,用户卖家的数据就会出现在表中。

我见过很多解决方案,但所有解决方案都失败了。现在我又回到了起点。

问题:我不知道如何在另一个数组 Angular 中正确调用数组。

html:

<div id="main" class="row" ng-controller='payment'>
<div>
<label>Client Name:</label><br/>
<select class="form-control input-sm" name="client_name">
<option ng-repeat="names in name" value="{{names.name}}" ng-model="select">{{names.name}}</option>
</select>
</div>
<div id="seller" class="margins_top">
<table class="table table-bordered">
<thead>
<tr>
<td>Seller Name</td>
<td>Payment</td>
<td>Date</td>
<td>Payment Receipt</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="sellers in seller">
<td>{{sellers.sellername}}</td>
<td>{{sellers.payment}}</td>
<td>{{sellers.date}}</td>
<td>{{sellers.receipt}}</td>
</tr>
</tbody>
</table>
</div><!-- /#seller -->
</div>

Controller js:

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


app.controller('payment',function($scope,$http){
getrecord(); // Load all available tasks
function getrecord(){
$http.post("angular/ajax/payment.php").success(function(data){
$scope.name = data;
$scope.seller = data[0].sallers;
});
}
});

我已经创建了 fiddle ,但它没有使用,但我仍然添加它。

Fiddle

最佳答案

试试这样

在 HTML 中

    <select class="form-control input-sm" name="client_name" ng-model="select">
<option ng-repeat="names in name" value="{{names.name}}"> {{names.name}}</option>
</select>

在你的 JS 中

$scope.$watch('select', function(newvalue) {
angular.forEach($scope.name, function(value, key) {
if(value.name == newvalue) {
$scope.seller = value.sallers;
}
});
});

关于javascript - 在angularjs中的另一个数组中调用json数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24884951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com