Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am working in extjs4 MVC where I have been working on task to create question answer page functionality.There are 4 questions to be displayed with there options.I have getting all the selected questions and answers in controller.But I didnot know how to send to srver side using models method.I am getting stuck at this point.

Here is my some controller code 1)

check:function()
    {
        console.log("Inside check function.");
        //creating objects in javascript
          var obj=new Object();
          for(var i=0;i<=5;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);
                    }// End of if statment
                }// End of inner for loop
          }//End of outer for loop

    }// End of check function

2)here is I have getting some output in firebug

questionId=1 value=Aus QbqnsController.js:39
questionId=2 value=india QbqnsController.js:39
questionId=3 value=England QbqnsController.js:39
questionId=4 value=Srilanka 

Actually i want to use model class methods save() . but how can I use it. please give me some suggestions.

3)here is my model classs

Ext.define('Balaee.model.qb.QbqnsModel',{
    extend: 'Ext.data.Model',
    idproperty:'questionId',//fields property first position pk.
    fields: ['questionId','question','languageId','userId','creationTime','questionStatusId','keyword'],
    hasMany:{
            model:'Balaee.model.qb.QbqnsoptionModel',
            foreignKey:'questionId',
            name:'options',
        },


        proxy:
        {
            type:'ajax',
            api:
            {
                    read:'http://localhost/balaee/balaee/index.php?r=QuestionBank/qbpaper/setuseranswer',
                    create:'http://localhost/balaee/balaee/index.php?r=QuestionBank/qbpaper/setuseranswer',
            },//end of api
            reader:
            {
                    type:'json',
            },//end of reader
            writer:
            {
                    type:'json',
                    root:'records',
            },//End of writer
        }   

});
share|improve this question

2 Answers

up vote 1 down vote accepted

If you're using Ext MVC and you're questions are model instances stored inside a store, you can use store.sync() which will batch the data in different states (add, edit, deletes etc) and sync them with the relevant store or model proxy url, or the api urls specified.

This has the benefit of sending arrays of objects back in a single request, but then of course you need to separate them on the server side before processing.

share|improve this answer
Thanks for your reply. – Pravin Mane Jan 23 at 6:43

Inside your function you can send them using Ext.Ajax.request

    Ext.Ajax.request({

      url: 'your_server_page.php ',
        params: { 
           Your_Object_Name  : JSON.stringify(Your_Object_Array)
       }                                        
});
share|improve this answer
thanks. I am using MVC. so which method of model should I call.please give me some information. – Pravin Mane Jan 22 at 14:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.