I have javascript function object EmployeeClass
. Field of this objects are mapped by hard-coding attributes.
An event is bind on jqgrid jqGridAddEditAfterSubmit
. Inside this function i am able to read json string object presenting a row being updated/added.
The json string is represented something like following:
{
"Id":"xxx",
"FirstName":"Mr. B",
"LastName":"Ross",
...
}
Function object definition:
//EMPLOYEE
function EmployeeClass(empJson){
this.Id = empJson.Id;
this.FirstName = empJson.FirstName;
this.LastName = empJson.LastName;
...
...
}
The sample of code used inside binding function is following:
$("gridid").bind("jqGridAddEditAfterSubmit", function (e, rowid, event) {
var rowData = ...
..
..
//construct object for server
var oObject = new EmployeeClass(rowData);
//CALL SERVER SIDE API for store
SERVERREMOTE.call(oOject,'saveEmployee',...);
});
Question
Above code works great if no fields are added dynamically. Meaning, serverside can add custom fields and those fields are dynamically added into jqgrid, which manages display/edit/add functionally beautifully. But, my issue is now, how to submit my EmployeeClass
object to server with dynamically added attributes? I need some how extend my EmployeeClass
inside my binding function jqGridAddEditAfterSubmit
so that i capture all the attributes passed by jqgrid and transform to EmployeeClass
Hope this scenario explains my issue. It is all about extending javascript function object dynamically at run-time.
ANSWER