早上好! 我生成表单值对象的文字和我将它们存储在一个数组如下将对象文字插入对象的数组
var persons = {};// I want all the objects in the array to be inserted here so that I can stringify it and send via Ajax
var array = [];// where I store the object literals
var courses = {};
course['name'] = $('#course').val();
array.push(courses);
var students = {};
students['first'] = $('#first_name').val();
students['last'] = $('#last_name').val();
students['age'] = $('age').val();
array.push(courses);
// I tried this after the help I got this morning but it does not create multiple objects. When there are many successive values, the data sent is empty
var persons = {
courses: {
name: $('#course').val(),
},
students: {
name: $('#first_name').val(),
last: $('#last_name').val(),
age: $('#age').val(),
},
};
请有谁知道我可以创建几个学生,让他们在过程中的同一对象名称?
如果你只想使用'stringify',为什么不'JSON.stringify({[] })'? – eisbehr
首先,“course ['name'] = $('#course')。val();”将会是“courses ['name'] = $('#course')。val();” – Arnab003