1. #1
    Sencha User
    Join Date
    Jan 2008
    Posts
    21
    Vote Rating
    0
    randielCoder is on a distinguished road

      0  

    Default Function to generate dinamic JsonStore

    Function to generate dinamic JsonStore


    Hi,

    I need a function that generate a JsonStore, i invoke with a servlet name for example:
    My code use eval function to create my JsonStore, but i get this error:

    "this.proxy is null or not an object"

    In Chrome browser, i get this object with the correct data loaded:
    data: Object <--- i review this object and contain all my data.

    My function is:

    Code:
    function genProxy(pProced){
    	if (pProced==null) {
    		alert("Error: El Procedimiento Almacenado no existe en la base de datos.");
    		return false;
    	}
    	/* Conectar a Datos */
    	dbStr = "var tramaStr = $.ajax({ " +
    				"url: '../../" + pProced + "'," +
    				"async: false" +
    			"}).responseText;";
    	eval(dbStr);
    	eval("varJSON = " + tramaStr);
    	//alert(varJSON);
    	
    	/* Generar el proxeador */
    	strName = 'get' + pProced;
    	strCommand = strName + " = Ext.extend(Ext.data.JsonStore, { " + 
    					"constructor: function(cfg) {	" + 
    						"cfg = cfg || {};" + 
    						strName + ".superclass.constructor.call(this, Ext.apply({" + 
    							"storeId: '" + strName + "'," + 
    							"root: 'rows'," + 
    							"data: varJSON," + 
     							"autoLoad: true," + 
    							"fields: varJSON['metadata']['fields']" + 
    						"}, cfg));" + 
    					"}" + 
    				"});";
    	eval(strCommand);
    	strExec = "new " + strName + "();";
    	//strLoad = strName + ".loadData(varJSON);";
    	try {
    		eval(strExec);
    		eval(strLoad);
    		//alert(vardump(getConsultaMoneda));
    		return true;
    	} catch(e){
    		return false;
    	}
    }
    Please i need help. Thanks in advance.

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    82
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Why are you doing all this with evals and why do you even need to create a class for the store? Isn't a simple class instance enough?

    ps. Your problem is that you shouldn't load a store that is defined with 'data' (remove autoLoad:true).

  3. #3
    Ext JS Premium Member devtig's Avatar
    Join Date
    Jan 2010
    Location
    Rotterdam, The Netherlands
    Posts
    388
    Vote Rating
    13
    devtig will become famous soon enough

      0  

    Default


    Why do you use eval? It doesn't serve a purpose at all and it prevents you from making full use of the Ext framework.

  4. #4
    Sencha User
    Join Date
    Jan 2008
    Posts
    21
    Vote Rating
    0
    randielCoder is on a distinguished road

      0  

    Default Ext Designer replace fields mapping of JsonStore

    Ext Designer replace fields mapping of JsonStore


    Quote Originally Posted by Condor View Post
    Why are you doing all this with evals and why do you even need to create a class for the store? Isn't a simple class instance enough?

    ps. Your problem is that you shouldn't load a store that is defined with 'data' (remove autoLoad:true).
    I use Ext Designer and this is a "data store" file automatically generate. I try to get my data (and metadata) with jQuery, then with the metadata to create that file and run (with eval). Otherwise would have to define each store and map it in the Ext Designer, I try to reduce this work.

    In the API Documentation indicates "data" attributes for JsonStore is valid.

    Thank you both

  5. #5
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    82
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Still, I don't see why you need to call eval at all.

    This works just fine:
    Code:
    function genProxy(pProced){
        if (!pProced) {
            alert("Error: El Procedimiento Almacenado no existe en la base de datos.");
            return false;
        }
        var tramaStr = $.ajax({
            url: '../../" + pProced,
            async: false
        }).responseText;
        var store = new Ext.data.JsonStore({
            storeId: 'get' + pProced,
            root: 'rows',
            data: Ext.decode(tramaStr),
            fields: varJSON.metadata.fields
        });
        return true;
    }
    ps. The JsonReader would automatically pickup on your fields if you would call the property 'metaData' instead of 'metadata'.
    Last edited by Condor; 29 Nov 2010 at 7:03 AM. Reason: Removed autoLoad:true

  6. #6
    Sencha User
    Join Date
    Jan 2008
    Posts
    21
    Vote Rating
    0
    randielCoder is on a distinguished road

      0  

    Default


    I get this error:

    Internet Explorer:
    "this.store.autoCreated" is null or not an object.

    Chrome:
    Uncaught TypeError: Cannot call method 'request' of undefined
    Ext.handleErrorext-all.js:7
    Ext.data.Store.Ext.extend.handleExceptionext-all.js:7
    Ext.data.Store.Ext.extend.loadext-all.js:7
    Ext.form.ComboBox.Ext.extend.doQueryext-all.js:11
    Ext.form.ComboBox.Ext.extend.onTriggerClickext-all.js:11
    K

    I understand that "eval" is not necessary. I use exactly your code. I've seen the json result with "alert" and is correct.

    Code:
    function genProxy(pProced){
        if (!pProced) {
            alert("Error: El Procedimiento Almacenado no existe en la base de datos.");
            return false;
        }
        var tramaStr = $.ajax({
            url: '../../' + pProced,
            async: false
        }).responseText;
    	jsonExt = Ext.decode(tramaStr);
        var store = new Ext.data.JsonStore({
            storeId: 'get' + pProced,
            root: 'rows',
            data: jsonExt,
            autoLoad: true,
            fields: jsonExt.metadata.fields
        });
        return true;
    }
    Last edited by randielCoder; 29 Nov 2010 at 7:06 AM. Reason: Add more information

  7. #7
    Sencha User
    Join Date
    Jan 2008
    Posts
    21
    Vote Rating
    0
    randielCoder is on a distinguished road

      0  

    Default


    My combo is defined:

    Code:
    items: [
    	{
    		xtype: 'combo',
    		fieldLabel: 'Moneda',
    		anchor: '100%',
    		labelStyle: '',
    		store: 'getConsultaMoneda',
    		valueField: 'CODIGO_MONEDA',
    		displayField: 'DESCRIPC_MONEDA',
    		triggerAction: 'all',
    		loadingText: 'Cargando...',
    		style: 'font-size:11px; font-family:Verdana;',
    		forceSelection: true,
    		selectOnFocus: true,
    		id: 'cmbMoneda'
    	}
    ]

  8. #8
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    82
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Also remove "autoLoad:true,".

  9. #9
    Sencha User
    Join Date
    Jan 2008
    Posts
    21
    Vote Rating
    0
    randielCoder is on a distinguished road

      0  

    Default


    I do it. But, i have the same error.

  10. #10
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    82
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Your combobox also needs to be mode:'local', since you're now loading your own data.

Similar Threads

  1. Dinamic Textfields with ComboBox
    By michelmfreitas in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 14 Oct 2010, 10:22 AM
  2. Dinamic Textfields with ComboBox
    By michelmfreitas in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 14 Oct 2010, 10:08 AM
  3. Custom mapping function for JsonStore
    By csext5 in forum Ext Designer: Help & Discussion
    Replies: 1
    Last Post: 29 Jul 2010, 5:07 AM
  4. Dinamic Grid
    By PHP Detonator in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 21 Nov 2008, 12:07 AM
  5. Menu Dinamic.
    By Perfect Lion in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 4 Oct 2007, 12:48 AM

Thread Participants: 2

Tags for this Thread