Here's my json :
这是我的json:
[
{
"name": "1QQQJohnQQQ11_12_1998",
"age" : "ads"
},
{
"name": "2QQQEvaQQQ05_11_1989",
"age" : "ads"
},
{
"name": "3QQQCasperQQQ12_06_1994",
"age" : "ads"
},
{
"name": "4QQQBeanQQQ30_12_1996",
"age" : "ads"
}]
and javascript file :
和javascript文件:
var app = angular.module('app', []);
app.service('service', function($http, $q){
var deferred = $q.defer();
$http.get("datesss.json").then(function(data){
deferred.resolve(data);
});
this.getNames = function(){
return deferred.promise;
}
});
app.controller('secondCtrl', function($scope, service){
var promise = service.getNames();
promise.then(function(data){
$scope.names = data.data;
var namesplit = $scope.names
namesplit.map(function(item) {
item.type = item.name.split('QQQ')[0];
item.date = item.name.split('QQQ')[1];
item.name = item.name.split('QQQ')[2];
});
console.log(namesplit);
});
});
I had to split name from json by "QQQ" in javascript file. In console.log(namesplit)
i have everything ("type", "date", "name") listed good.
我不得不在javascript文件中用“QQQ”从json中分割名称。在console.log(namesplit)中,我将所有内容(“类型”,“日期”,“名称”)列为好。
What i need to do is write "type", "date", and "name" in table. I tried this :
我需要做的是在表格中写下“type”,“date”和“name”。我试过这个:
<thead>
<tr>
<th class="text-center">type</th>
<th class="text-center">date</th>
<th class="text-center">name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="name in namesplit">
<td>{{name.type}}</td>
<td>{{name.date}}</td>
<td>{{name.name}}</td>
</tr>
</tbody>
But it didn't work. Someone help? Thanks in advance.
但它没有用。有人帮忙吗?提前致谢。
1 个解决方案
#1
2
Change all the occurrences of namesplit
to $scope.namesplit
in your controller.
将所有出现的namesplit更改为控制器中的$ scope.namesplit。
Otherwise here, ng-repeat="name in namesplit
", there is no scope variable called namesplit
否则在这里,ng-repeat =“namesplit中的名称”,没有名为namesplit的范围变量
#1
2
Change all the occurrences of namesplit
to $scope.namesplit
in your controller.
将所有出现的namesplit更改为控制器中的$ scope.namesplit。
Otherwise here, ng-repeat="name in namesplit
", there is no scope variable called namesplit
否则在这里,ng-repeat =“namesplit中的名称”,没有名为namesplit的范围变量