사용자 제출에 의해 동적으로 채워지는 데이터베이스 테이블에서 문자열을 가져 오기 때문에 길이가 다양한 문자열 배열이 있습니다. 그러나 긴 배열은 반복되는 6 개의 변수로 구성됩니다. 그래서 매 6 번째 인덱스에서 슬라이스하여 배열로 썰어 놓은 다음 해당 하위 배열 목록을 페이지에 인쇄합니다.하나의 긴 배열에서 하위 배열 목록을 만들고 인쇄하는 방법
이//I'm using Parse as my database and the find() method is one way you query it.
var search = [];
query.find({
success: function(results) {
//loop through results to get the key-value pair of each row
for (i = 0; i < results.length; i++){
activity = results[i].get("activity");
scene = results[i].get("location");
neighborhood = results[i].get("neighborhood");
date = results[i].get("date");
details = results[i].get("details");
time = results[i].get("time");
//Here I'm pushing the row of the six variables into an array, but since there will be multiple rows on the table from multiple submissions, the array will contain however many rows there are.
search.push(activity, scene, neighborhood, date, details, time);
//my second array
var search2 = [];
//This is that part I'm unsure of. I want to loop through the search array slicing it at every 6th index creating multiple sub arrays. I then want to write the list of those sub arrays to the page
for(i=0; i < search.length; i+=6){
search2 = search.slice(0,6);
}
//this is the div I want to write the arrays to.
$("#mainDiv").text(search2);
};// closes success function
을! 감사. – Spilot