簡體   English   中英

Meteor中長度為0的非空數組

[英]non empty array with length=0 in Meteor

const items = [];
Meteor.http.call("GET", url,function(error,result){  
  $.each(JSON.parse(result.content), function(key, value){
    items.push(value)
  });
});

下面的代碼返回長度為0的非空數組項。如何迭代數組或通過鍵將所有值提取到數組?
在此輸入圖像描述

Meteor.http.call是一個Meteor.http.call的異步函數。 我能想到做你想做的快速方法如下:

const items = [];
Meteor.http.call("GET", url,function(error,result){  
  $.each(JSON.parse(result.content), function(key, value){
    items.push(value)
  });
  handleItems(items);
});

function handleItems(items) {
  console.log(items.length) // 1
  // Do what you want with the items array here.
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM