質問

I am new to using Dojo framework. I have implemented dgrid for collecting data and this works great for storing, querying, updating and deleting data from the client side during data entry. However once the dojo.store.memory data type has data i would like to use an ajax request to post the dojo object to the server.

I would like to post the data to the server in json format however i am unable to convert the object (myStore) to json string. Under is what i have attempted thus far:

JavaScript function

function SendForm(){
  var jsonIdObj = JSON.stringify(myStore);              

dojo.xhrPost({
   url:'processData',
   form:dojo.byId('myForm'),
   postData:jsonIdObj,
   success: function(){
        console.log('success');
    },
   error: function(){
    console.log('error occured');
    }
   }); 
}

Data Store

 var myStore = new dojo.store.Observable(new Memory({data: data, idProperty:"typeId"})); 

Data

var data = [{ id:"1",age:"33",idtype:"1" ,first_name: "Edward", surname: "Davis" },
             { id:"2",age:"41",idtype:"2" ,first_name: "Lewis", surname: "Holl"},
             { id:"3",age:"59",idtype:"3" ,first_name: "Fred", surname: "James"}];
役に立ちましたか?

解決

Firstly, you want to be stringifying store.data, not store itself. dojo/store/Memory maintains the data itself in the data property of the store.

Secondly, you probably don't want to specify both form and postData to your XHR call - you probably just want postData in this case. When form is specified to dojo.xhrPost, it gets converted into an object to pass to postData anyway.

Thirdly, if you're using Dojo 1.8 or newer, you should consider using the new dojo/request API.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top