[英]convert array from inside of returned object into select item list js
我在這里查看了有關如何執行此操作的幾個示例,但答案仍然暗示着我。
我有一個ajax調用,該調用返回一個具有幾個屬性以及其他對象數組的對象。 我想從每個內部對象中獲取2個屬性以創建一個列表。 現在,我有如下代碼:
myMethod: function(data){
$.each(data, function(){
$('#mySelectList').append($('<option></option>').text(data.Name).val(data.ID));
});
}
我也嘗試過JSON.stringify(data.Name)
,我認為這是必需的,但是我認為我訪問的屬性不正確。 在我的chrome開發工具中,返回的對象如下所示:
Object {BooleanProperty1: true, BooleanProperty2: true, Rows: Array[9]}
當我深入到行中時:
0: Object
ID: 1
Title: "SomeTitle"
SomeOtherProperties: propertyData
//more properties
2: Object
ID: 2
Title: "SomeOtherTitle"
SomeOtherProperties: propertyData
//more properties
//more objects
創建列表時,如何訪問此數組內的屬性以使用它們?
data
是響應還是完整的數組,以及其中需要的每個元素,為此,您需要在函數中指定索引和element
參數,並從element
讀取值
$.each(data.Rows, function(index, element){
$('#mySelectList').append($('<option></option>').text(element.Name).val(element.ID));
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.