我使用AngularJs / Laravel应用程序。我尝试访问每个工厂中的项目。实际上,我无法打印出整个制造对象,但是我想知道如何访问这些项目,以便可以遍历它们并显示它们。
这是我的PHP控制器发送Json数据
public function show($id)
{
$facture = Facture::where('id', '=', $id)->with('items')->get();
return Response::json($facture);
}
这是我简化的AngularJs控制器
$http.get('api/factures/' + $stateParams.factureId).success(function(data) {
$scope.facture = data;
});
而实际上
{{发票| json}}打印此:
[
{
"id": 10200,
"client_id": 1,
"lead_id": 1,
"courtedescription": "Description test",
"etat": "En attente",
"created_at": "2014-12-30 10:01:46",
"updated_at": "2014-12-30 10:01:46",
"items": [
{
"id": 1,
"facture_id": 10200,
"description": "Item numéro 1",
"prix": "15.00",
"tps": "0.75",
"tvq": "1.50",
"grandtotal": "17.25",
"created_at": "2014-12-30 10:01:46",
"updated_at": "2014-12-30 10:01:46"
},
{
"id": 2,
"facture_id": 10200,
"description": "Deuxième item quoi",
"prix": "135.00",
"tps": "6.75",
"tvq": "13.47",
"grandtotal": "155.22",
"created_at": "2014-12-30 10:01:46",
"updated_at": "2014-12-30 10:01:46"
}
]
}
]
以下是简化的Plunkr,专注于基本功能:http ://plnkr.co/edit/fZmb4fAX0GJCDH2cpxwQ?p=preview
我怎样才能获得这些物品?
您可以将future值用作普通数组,因为它在视图范围内。
例如,如果您想要数组中第一个对象的ID,则可以使用以下代码
{{facture[0].id |json}}
如果您想遍历每个值,请查看https://docs.angularjs.org/api/ng/directive/ngRepeat
希望这可以帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句