Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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 有办法查一下名单吗?离子骨架_Javascript_Angularjs_Ionic Framework - Fatal编程技术网

Javascript 有办法查一下名单吗?离子骨架

Javascript 有办法查一下名单吗?离子骨架,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,嗨,我有一张物品清单。像这样: // Some fake testing data var chats = [{ id: 0, name: 'Ben Sparrow', lastText: 'London', face: 'img/ben.png' }, { id: 1, name: 'Max Lynx', lastText: 'Paris', face: 'img/max.png' }, { id: 2,

嗨,我有一张物品清单。像这样:

// Some fake testing data
  var chats = [{
    id: 0,
    name: 'Ben Sparrow',
    lastText: 'London',
    face: 'img/ben.png'
  }, {
    id: 1,
    name: 'Max Lynx',
    lastText: 'Paris',
    face: 'img/max.png'
  }, {
    id: 2,
    name: 'Adam Bradleyson',
    lastText: 'Berlin',
    face: 'img/adam.jpg'
  }, {
    id: 3,
    name: 'Perry Governor',
    lastText: 'Tokio',
    face: 'img/perry.png'
  }, {
    id: 4,
    name: 'Mike Harrington',
    lastText: 'Milan',
    face: 'img/mike.png'
  }];
正如您所看到的,每个列表项都有一个名为city的lastText。这是我的视图文件: `


{{cityname}}
{{dweather}}

删去
`


我有一个函数
getWeather(chat.lastText)
,它返回所选城市的天气。变量
cityname
dweather
。我想显示每个列表项的lastText变量中存储的每个城市的天气。但它只显示每个列表项的第一个城市的天气。我的问题是如何使其成为可能?

我不知道您的
getWeather
函数是什么样子,但您应该将结果分配给一个“全局”范围变量,而不是将其放在
chat
对象中:

$scope.getWeather = function(chat) {
    // get weather
    weatherService.getWeather(chat.lastText).then(function(response) {
        var weatherResult = response.data;
        chat.cityname = weatherResult.cityname;
        chat.dweather = weatherResult.dweather;
    });
}
然后可以如下所示显示:

<ion-item ng-init="getWeather(chat)">
    {{ chat.cityname }}
    {{ chat.dweather }}
</ion-item>

{{chat.cityname}
{{chat.dweather}}
nginit
中删除
getWeather(chat.lastText)
,然后尝试以下方法
ng init
ng repeat
中仅调用一次


{{getWeather(chat.lastText)}
{{cityname}}
{{dweather}}

删去
可能与我以前尝试过的相同。它会导致一个硬循环。列表中的所有项目都会快速通过列表视图而不停止。它会导致循环,那么请在问题中包括
getWeather
函数的外观。就像我说的,因为你没有包括你的代码,我做了一些假设,你必须根据它的编写方式将这些假设应用到你自己的代码中
<ion-item ng-init="getWeather(chat)">
    {{ chat.cityname }}
    {{ chat.dweather }}
</ion-item>