![](/img/trans.png)
[英]How to parse data from an extracted JSON object property using AngularJS?
[英]How to store JSON object data into a variable once that data is extracted with a function ()?
我有一個 JSON 文件,里面有圖片庫。 我正在使用 function 提取該數據,但我希望一旦提取該數據以將其存儲到變量中,以便從現在開始我可以使用該變量進行數據引用。 我怎樣才能做到這一點
function getJsonphotos() {
$.getJSON("./json/photos.json", displayImages);
}
function displayImages(data) {
data.forEach(function (item) {
storeContainer.append(`<<img id=${item.id} src=${item.location} />)
});
let jsonArrayVariable = [] ;
我應該如何將照片放在jsonArrayVariable
變量中。
您在回調 function 之外創建一個數組。 然后將每個項目推送到數組中。
let jsonArrayVariable = [];
function displayImages(data) {
data.forEach(item => {
storeContainer.append(`<img id=${item.id} src=${item.location} />`);
jsonArrayVariable.push(item);
});
我是這樣做的:
arrayImages = [];
function getJsonphotos(data) {
$.getJSON("./json/photos.json",function (data){
arrayImages = data;
displayImages(data);
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.