open menu
// typically will you have a json structure as a response from a gj.ajax // we start up the store. gj.store.setData({ 'customerdata' : respons });
// update the whole store // mark the second parameter. This is optional. But if it is there the store will parse this are of the DOM and update the elements // connected to the store (see exampel next page) gj.store.updateData({ 'customerdata' : newRespons }, $('#myAppDOMid')); // update a known key in the store // your will get an error if you try to update a key that do not exist // DOM element connected to this store key will also be updated gj.store.set('customerdata.firstname', 'Donald');
// get all the data in store var flag = true ; // set this to true of if you want to clear 'changetracker' in store var storeData = gj.store.getData(flag); // return true if something has been changed in store since store was started OR getData with flag = true was executed var status = gj.store.hasDataChanged(/*optinal put a key in here and get the status only on this key*/); //This will just display the changes to the store. A debug function gj.store.showStoreChanges() //get a spesific value var myVal = gj.store.get('customerdata.firstname'); //callbackfunction if a spesific key get changed gj.store.watch('customerdata.firstname',function(newValue,oldValue,key){ console.error('firstname changed from ' + oldValue + ' to ' + newValue); });
// example on how to set up your template on different HTML elements
// pipe your storevalue trough a custom function befoe output is set on HTML element // using gj-store-function <span gj-store-key="customerdata.firstname" gj-store-function="myApplication.utility.SetupFullname"></span> <input type="text" gj-store-key="customerdata.firstname" gj-store-function="myApplication.utility.SetupFullname"></input> myApplication.utility.SetupFullname = function(value){ return value + ' ' + gj.store.get('customerdata.lastname'); } // pipe your storevalue trough a custom function befoe output is set to an attribute on the HTML element // using gj-store-function + gj-store-target <div gj-store-key="customerdata.amount" gj-store-function="myApplication.utility.hideOrShowCustomer" gj-store-target="style"> Rich guy: <span gj-store-key="customerdata.firstname" gj-store-function="myApplication.utility.SetupFullname"></span> </div> myApplication.utility.hideOrShowCustomer = function(value){ return (value > 3000000 ? 'display:block;' : 'display:none;' );; }