getLocationsArray
の戻り値をgetLocationsメソッドの外部に渡す方法がわかりません。これはどうすればsetMarkers
メソッドで使用できますか?もちろん、オブジェクトリテラル内でメソッドや変数を内部的に呼び出すときは、例えばAPP.map.setMarkers
を使用することができます。ありがとう。オブジェクトリテラルメソッドに関する非同期値の受け渡し
init: function(){
...ETC...
APP.map.getLocations()
APP.map.setMarkers(center, radius, map)
},
getLocations: function() {
$.getJSON('data/json/locations.json', function(data) {
var locations = data
var getLocationsArray = $.map(locations, function(value, index) {
return [value]
})
console.log(getLocationsArray)
return getLocationsArray
})
console.log('getLocationsArray2', getLocationsArray2)
return getLocationsArray2
},
setMarkers: function(center, radius, map) {
**getLocationsArray**.forEach (function (hello) {
..ETC..
}
あなたはあなたの質問をより明確にし、より多くのコードを提供することができますか? – sehrob
'jQuery.getJSON'は約束を返します - それを使用します。 – ankr