我在 extjs4 MVC 中工作,我一直被困在如何在单个请求中发送对象数组的问题上。我知道如何将单个对象发送到服务器。
1)这是我的一些控制器代码:-
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].name1=name;
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 Infooooooooo:" + check.get('option'));
}// End of if statment
}// 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)型号类:---
Ext.define('Balaee.model.qb.QbquestionoptionModel',{
extend: 'Ext.data.Model',
idproperty:'',//fields property first position pk.
fields: ['optionId','questionId','isAnswer','option','media','keyword','mediaTypeId',],
/*associations:[
{type:'BelongsTo', model:'Mediatype', foreignKey:'mediaTypeId'},
{type:'BelongsTo', model:'Qbquestion', foreignKey:'questionId'},
{type:'HasMany', model:'Qbregistereduserfreequestionawnser', foreignKey:'answerOptionId'},
]*/
});
3)这是我的商店:---
Ext.define('Balaee.store.qb.QbquestionoptionStore',{
extend: 'Ext.data.Store',
model: 'Balaee.model.qb.QbquestionoptionModel',
//autoLoad: true,
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',
//destroy: ,
},//End of api
reader:
{
type:'json',
//root: ,
//successProperty: ,
},//End of reader
writer:
{
type:'json',
root:'data'
}
}//End of proxy
});//End of store
我该如何解决这个问题?请给一些建议....