访问angularjs

时间:2016-03-29 10:17:21

标签: angularjs

我有这样的json结构:

{
  "states": [
 {
  "images": {
    "small": "http://userserve-ak.last.fm/serve/34s/88221849.png",
    "medium": "http://userserve-ak.last.fm/serve/64s/88221849.png",
    "large": "http://userserve-ak.last.fm/serve/126/88221849.png",
    "extralarge": "http://userserve-ak.last.fm/serve/300x300/88221849.png"
  },
  "capital": "Amravathi",
  "name": "Andhra Pradesh"
},
{
  "images": {
    "small": "http://userserve-ak.last.fm/serve/34s/96506699.png",
    "medium": "http://userserve-ak.last.fm/serve/64s/96506699.png",
    "large": "http://userserve-ak.last.fm/serve/126/96506699.png",
    "extralarge": "http://userserve-ak.last.fm/serve/300x300/96506699.png"
  },
  "capital": "Itanagar",
  "name": "Arunachal Pradesh"
},

我想使用promise使用angularjs工厂方法返回json。我有两个空对象状态{}和大写{}。当我使用

(function(promise) { return [promise[0].data.states,   promise[0].data.states.capital]; })
    .subscribe(function(result) {
        $scope.states = result[0].slice(0, 5);
        $scope.capitals = result[1].slice(0, 5);

状态对象获取所有值但是资本对象为空。我想从该json只访问大写选项并将其存储在大写对象中。我怎么能这样做,请给我一些建议。

1 个答案:

答案 0 :(得分:0)

您可以使用.map(),如下所示:

<input type="file"/>