[英]How to create array in Javascript?
我想從數組中的查詢中輸出兩個表列的情況。 理想情況下,我想輸出一個ID_1,然后輸出第二個ID_2,並且在將所有ID存儲在數組中之后,我想遍歷該數組以檢查ID_1是否大於0,是否要使用匹配的ID_2來隱藏元素。 這是我到目前為止的代碼:
var records = [];
~[tlist_sql;
SELECT ID_1, ID_2
FROM SLOTS
]
records.push("~(ID_1)","~(ID_2)");
[/tlist_sql]
for(var i=0; i< records.length; i++){
//if ID_2 is greater than 0
if(records[i].idTwo > 0){
var test = ('#row_' + records[i].idOne).val();
alert(test)
//here I want to use ID_1 to hide row
$j('#row_' + records[i].idOne).parent('.hideElement').hide();
$j('#button1').hide();
}
}
這是我的數組記錄的樣子:
[-1,2050,-1,2046,15,2048,0,2044,10,2051,0,2047]
因此,如您在此數組中看到的,如果ID_1的值為15,10且ID_2的值為2048,2051的語句僅傳遞兩條記錄。 我當前的代碼未使用正確的值,好像id是如何拆分的。 有誰知道我應該如何尋找ID_1,然后尋找ID_2,在這種情況下,數組是最好的選擇嗎? 謝謝。
大概是這樣的:
var records = [];
~[tlist_sql;
SELECT ID_1, ID_2
FROM SLOTS
]
records.push({
'idOne' : "~(ID_1)",
'idTwo' : "~(ID_2)"
});
[/tlist_sql]
然后在訪問這些記錄時:
for(var i=0; i< records.length; i++){
//if ID_1 is greater than 0
if(records[i].idOne > 0){
//here I want to use ID_2 to hide row that has matching ID
$j('#row_' + records[i].idTwo).parent('.hideElement').hide();
$j('#button1').hide();
}
}
創建一個對象:
var records = [];
~[tlist_sql;
SELECT ID_1, ID_2
FROM SLOTS
]
records.push({id1:":~(ID_1)",id2:"~(ID_2)"});
[/tlist_sql]
for(var i=0; i< records.length; i++){
//if ID_1 is greater than 0
if(records[i].id1 > 0){
//here I want to use ID_2 to hide row that has matching ID
$j('#row_' + records[i].id2).parent('.hideElement').hide();
$j('#button1').hide();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.