我在jquery
中尝试了以下代码行 import java.util.ArrayList;
import java.util.Date;
public class AmusementPark {
private ArrayList<Ticket> tickets;
private ArrayList<Merchandise> merchandise;
private String name;
AmusementPark(String name){
this.name=name;
this.tickets = new ArrayList<Ticket>();
this.merchandise= new ArrayList<Merchandise>();
}
String getName(){
return name;
}
public ArrayList<String> getTicketDates(){
ArrayList<String> theDateArray= new ArrayList<>();
int i;
String date = Ticket.getDate(); //This is not working. See Reason Below.
for (i=0; i<tickets.size(); i++){
if(tickets.get(i).getPurchased()== false){
theDateArray.add(date);
}
}return theDateArray;
}
}
在控制台数据中就像
0 : 宾语 1 : 阵列(4) 0 : 阵列(1) 1 : 阵列(2) 0 : 宾语 物理 : “150.00 / 200” 状态 : “通过” 的原 : 宾语 1 : 宾语 科学 : “400.00 / 600” 状态 : “通过” 的原 : 宾语 ...........
我希望li中的数据看起来像
每个科目的标记
<h5>Marks per Subjects</h5>
<ul id="subjectsMarks">
</ul>
$.ajax({
url: 'index.php?action=fetchStudentIfResultFound',
type: 'POST',
dataType: 'JSON',
...
...
for(i=0; i<data[1].length; i++)
{
$("#subjectsMarks li").html(key[1][i] + ':' + data[1][i]+ "<br/>"+data[1]["Status"]);
}
});
请帮帮我!!!
答案 0 :(得分:1)
从后端修改数据并向数据添加键,如下所示,很容易知道必须循环的地方,不需要知道何时停止
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXX";
const string authToken = "909dajhdusa78798324ndkjsahd";
TwilioClient.Init(accountSid, authToken);
var to = new PhoneNumber("+919000000000");
var from = new PhoneNumber("+919000000000");
var call = CallResource.Create(to,
from,
url: new Uri("http://twimlets.com/echo?Twiml=test")); //Not working
call = CallResource.Create(to,
from,
url: new Uri("http://twimlets.com/echo?Twiml=<Response><Say>testing</Say></Response>"));//Not working
call = CallResource.Create(to,
from,
url: new Uri("http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E"));//Not working
Console.WriteLine(call.Sid);
使用以下代码尝试循环
var data: {
student: {
"_id": {
"$id": "5715f58299fbad800100003a"
},
"student_id": 36,
"registration_temp_perm_no": "453654",
"roll_no": "31",
"admission_date": "04/12/2016",
"first_name": "Momin",
"middle_name": "Bashir",
"last_name": "Rather",
"dob": "7/9/1995",
"gender": "Male",
"blood_group": "",
"birth_place": "",
"nationality": "",
"language": "",
"religion": "Islam"...
},
marks: {
subjects: [
{
"Physics": "150.00/200",
"Status": "Pass"
},
{
"Science": "400.00/600",
"Status": "Pass"
}
],
"Total Marks": "550/800",
"Grade": "Ist",
}
}
第二版循环
//Without modify json from backend
var allSubjects=data[1][1];
//With modify json from backend
var allSubjects=data[1][1]['Subjects'];
for(var i in allSubjects){
var keysOfObject=Object.Keys(allSubjects[i]);
$("#subjectsMarks li").html(keysOfObject[0] + ':' + allSubjects[i][keysOfObject[0]]+ "<br/>"allSubjects[i]["Status"]);
/* //console.log(allSubjects[i].keysOfObject[0], keysOfObject[0])
console.log(allSubjects[i]);*/
}