javascript - 带有 ui.bootstrap 的 Angularjs 和 jquery.datatable - 需要使用循环在 json 中显示条目
问题描述
我需要在循环中显示 json 的条目。我是 js 和 angular 的新手,我不知道如何在下面代码的标记位置输入 for。我需要知道做所有的代码,这只是一个更大的项目的测试。
<?php
$estudent[]=array(
"name" => "luis",
"age" => "10");
$estudent[]=array(
"name" => "maria",
"age" => "12");
$objJson=json_encode($estudent);
?>
//here is the js
<script>
var json=eval(<?php echo $objJson; ?>);
//Angularjs and jquery.datatable with ui.bootstrap and ui.utils
var app=angular.module('formvalid', ['ui.bootstrap','ui.utils']);
app.controller('validationCtrl',function($scope){
$scope.data = [
[ //i need to use a loop for show all the studens
json[0].name,
json[0].age,
],
[ //i need to use a loop for show all the studens
json[1].name,
json[1].age,
],
]
$scope.dataTableOpt = {
//custom datatable options
// or load data through ajax call also
"aLengthMenu": [[10, 50, 100,-1], [10, 50, 100,'All']],
};
});
</script>
解决方案
对于此循环,您可以使用:
$scope.data = [];
angular.forEach(json, (item) => {
// here you can get item.age and item.name
$scope.data.push(item);
});
在此循环结束时,您$scope.data
将拥有所有学生
推荐阅读
- android - 在 AsyncTask 上尝试使用 SQLite 检索数据的奇怪行为
- javascript - 最初加载 webpack 时查询的数据消失,然后当我转到网站上的其他页面并返回时出现
- label - Jena:推理规则的标签定义错误
- laravel - 试图获取非对象的属性“image_url”(查看:/app/resources/views/library.blade.php)
- mongodb - 使用 mongoose 在 mongodb 集合中添加带有字符串的电子邮件地址
- r - 重新排列 R 中热图的数据框
- youtube - 为什么我的 YouTube 订阅按钮变暗且无法点击?
- laravel - 在 PDF 上导出希腊字符显示为框
- amazon-web-services - 如何增加 AWS CPU 积分余额降至零?
- javascript - 异步等待在带有回调的函数调用中无法正常工作