我是AngularJs的新手。我在第一页上检索数据(来自json数组),我想要做的是当我点击列表中的一个项目时,它会在第二页上显示current id
,date
,amount
和category
。但我不知道如何展示current id
,date
,amount
和category
。
这是我的控制器:
.controller('RegistreCtrl', function ($scope, $stateParams,factotransaction,$state) {
console.log("coucou");
var mytoken = sessionStorage.getItem('token');
factotransaction.send(mytoken).then(function(conf){
console.log(conf);
$scope.datab = conf.data;
})
$scope.operation = function(){
$state.go('app.operation');
}
})
.controller('OperationCtrl', function ($scope, $stateParams,factotransaction) {
var mytoken = sessionStorage.getItem('token');
factotransaction.send(mytoken).then(function(conf){
console.log(conf);
$scope.datab = conf.data;
})
})
和我对第一页的看法:
<ion-view view-title="Registre">
<ion-content>
<h1>Registre</h1>
<ul class="list" ng-repeat="item in datab track by $index">
<li class="item" ng-repeat="mytitle in item.assignation" ng-click="operation()">
{{item.date | myDate}}--
{{mytitle.category}}--{{mytitle.amount}}€
</li>
</ul>
</ion-content>
</ion-view>
和第二页的视图(现在几乎为空):
<ion-view view-title="Registre">
<ion-content>
<h1>Operation</h1>
<div class="card">
</div>
</ion-content>
</ion-view>
您是否知道如何管理?
答案 0 :(得分:1)
<ion-view view-title="Registre">
<ion-content>
<h1>Registre</h1>
<ul class="list" ng-repeat="item in datab track by $index">
you can try to pass some sort of indicator with the operation function, id maybe?
<li class="item" ng-repeat="mytitle in item.assignation" ng-click="operation(item.id)">
{{item.date | myDate}}--
{{mytitle.category}}--{{mytitle.amount}}€
</li>
</ul>
</ion-content>
</ion-view>
然后在这里,
$scope.operation = function(id){
$state.go('app.operation', { id: id });
}
不确定语法,但请检查。所以现在你有一个你可以玩的id。 在控制器中,
.controller('OperationCtrl', function ($scope, $stateParams,factotransaction) {
var mytoken = sessionStorage.getItem('token');
factotransaction.send(mytoken).then(function(conf){
console.log(conf);
conf.data.forEach(function(item){
if($stateParams.id === item.id) {
$scope.item = item;
}
});
});
})
然后在模板代码中使用$ scope.item