簡體   English   中英

將對象轉換為數組(angularjs和typeahead)

[英]Converting object to array (angularjs and typeahead)

假設我有一個如下所示的對象:{“1”:“2”,“3”:“4”}

我沒有直接訪問這些數據,所以當我通過ajax將其轉換為數組時如何? 像這樣:[{“1”:“2”},{“3”:“4”}]

PS:我在角度ui類型中使用此輸出數據,它不喜歡對象而只喜歡字符串。

這是一個片段:

var inputObj = {'1': '2', '3': '4'};
var output = [];
for (var key in inputObj) {
  // must create a temp object to set the key using a variable
  var tempObj = {};
  tempObj[key] = inputObj[key];
  output.push(tempObj);
}

console.log(output);

希望有所幫助!

暫無
暫無

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

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