JSFiddle - React, Tailwind, and code Playground

by SalesforceDev

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

JavaScript

function Employee(rowdata) {
  	this.Id = rowdata.Id;
    this.FirstName = rowdata.FirstName;
    this.LastName = rowdata.LastName;
    this.Designation = rowdata.Designation;
  }


	function getRowdata() {
  	//here lets say custom field 'Location' is added to grid
  	return {
    	"Id":"123",
      "FirstName":"John",
      "LastName":"Doe",
      "Designation":"Janitor",
      "Location":"Unknown"
    };
  
  }



  	var row = getRowdata();
    console.log(row);
    //construct serverside function object 'Employee'
    var oE = new Employee(row);
    console.log(oE);
    //how to add new custom attribute to above function object Employee? the new custom field is 'Location'
    
    for(var pName in row) {
    	console.log(pName);
      //
      oE[pName] = row[pName];
      //
    }
    
    console.log(oE);