Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在ionic中循环不同视图中的数据_Javascript_Angularjs_Html_Ionic Framework - Fatal编程技术网

Javascript 如何在ionic中循环不同视图中的数据

Javascript 如何在ionic中循环不同视图中的数据,javascript,angularjs,html,ionic-framework,Javascript,Angularjs,Html,Ionic Framework,我有五页不同的状态。第一页包含格式为的对象 { "good": { "good1": "good", "good2": "good", "good3": "good" }, "bad": { "bad1": "bad", "bad2": "bad", "bad3": "bad" }, "excellent": { "excellent1": "excellent", "excellent2": "excellen

我有五页不同的状态。第一页包含格式为的对象

{
  "good": {
    "good1": "good",
    "good2": "good",
    "good3": "good"
  },
  "bad": {
    "bad1": "bad",
    "bad2": "bad",
    "bad3": "bad"
  },
  "excellent": {
    "excellent1": "excellent",
    "excellent2": "excellent",
    "excellent3": "excellent"
  }
}
此对象保存到localstorage。
这是我试图展示我真正想要的东西的地方。场景是,good1值将在4个页面中循环,下次用下一个值(即good2)重定向到第一个页面,下一个值也将在相同的4个页面中循环,以此类推。我要怎么做才能解决这个问题?如果我的对象结构有问题,那么好的方法应该是什么呢?

我建议您将数据放在一个数据库中,这样在页面之间共享数据、将数据保存到本地存储并检索数据就会容易得多

.factory('amazingData',function() {
  var ohYeah = {
    'good':{
      'good1':'good',
      'good2':'good',
      'good3':'good'
    },
    'bad':{
      'bad1':'bad',
      'bad2':'bad',
      'bad3':'bad'
    },
    'excellent':{
      'excellent1':'excellent',
      'excellent2':'excellent',
      'excellent':'excellent'
    }
  };

  return ohYeah;
})
现在,您可以使用此服务并将其注入控制器:

.controller('homeCtrl',function($scope, amazingData){
  $scope.data=amazingData;
})
.controller('pageCtrl',function($scope, amazingData){
  $scope.data=amazingData;
})

所有页面的数据都是相同的。

我建议您将数据放在一个文件夹中,这样在页面之间共享数据、将数据保存到本地存储并检索数据就容易多了

.factory('amazingData',function() {
  var ohYeah = {
    'good':{
      'good1':'good',
      'good2':'good',
      'good3':'good'
    },
    'bad':{
      'bad1':'bad',
      'bad2':'bad',
      'bad3':'bad'
    },
    'excellent':{
      'excellent1':'excellent',
      'excellent2':'excellent',
      'excellent':'excellent'
    }
  };

  return ohYeah;
})
现在,您可以使用此服务并将其注入控制器:

.controller('homeCtrl',function($scope, amazingData){
  $scope.data=amazingData;
})
.controller('pageCtrl',function($scope, amazingData){
  $scope.data=amazingData;
})
所有页面的数据都将相同