Working in extjs4 MVC has presented a challenge for me as I try to figure out how to send an object array in a single request. While I understand how to send a single object to the server, sending multiple objects has proven to be more complex.
1)Below is a snippet of my controller code:
check:function () {
console.log("Inside check function.");
//creating objects in javascript
var obj = new Object();
for (var i = 0; i < 4; i++) {
var inputs = document.getElementsByName(i);
var radio = "";
for (var j = 0; j < inputs.length; j++) {
if (inputs[j].checked) {
name = inputs[j].name;
value = inputs[j].value;
obj[i] = {'questionId': name, 'option': value};
console.log("questionId=" + name + " value=" + value);
console.log("object name=" + obj[i].questionId + " Object value=" + obj[i].option);
var check = Ext.ModelManager.create(
{
questionId: name,
option: value,
}, 'Balaee.model.qb.QbquestionoptionModel');
console.log("User Info...:" + check.get('option'));
}// End of if statement
}// End of inner for loop
}//End of outer for loop
var storeObject = this.getStore('qb.QbquestionoptionStore');
storeObject.sync();
console.log("data send");
}// End of check function
2)My Model class definition:
Ext.define('Balaee.model.qb.QbquestionoptionModel',{
extend: 'Ext.data.Model',
idproperty:'',
fields: ['optionId','questionId','isAnswer','option','media','keyword','mediaTypeId',],
});
3)Here is my store configuration:
Ext.define('Balaee.store.qb.QbquestionoptionStore',{
extend: 'Ext.data.Store',
model: 'Balaee.model.qb.QbquestionoptionModel',
proxy:
{
type:'ajax',
api:
{
read:'http://localhost/balaee/Balaee/index.php?r=QuestionBank/qbpaper/SetUserAnswer11',
create: 'http://localhost/balaee/Balaee/index.php?r=QuestionBank/qbpaper/SetUserAnswer12',
update: 'http://localhost/balaee/Balaee/index.php?r=QuestionBank/qbpaper/SetUserAnswer13',
},
reader:
{
type:'json',
},
writer:
{
type:'json',
root:'data'
}
}
});
I am seeking suggestions on how to efficiently handle sending an object array in a single request. Any advice would be greatly appreciated.