Results 1 to 2 of 2

Thread: Error creating JSONReader with dynamic fields

  1. #1

    Default Error creating JSONReader with dynamic fields

    I've got a JSON call that returns some data in the format (There is much more, but here's an example):

    Code:
    {
        "headers": [
            {
                "label": "Title ID",
                "name": "id_title",
                "type": "integer"
            },
            {
                "label": "Title",
                "name": "title_decode",
                "type": "varchar"
            }
        ],
        "rows": [
            [
                "7",
                "Dr"
            ],
            [
                "11",
                "Lady"
            ],
            [
                "4",
                "Miss"
            ]
        ]
    }
    I've been using that for ages and extracting data from it, no problem.

    Now I'd like to render that information into a grid. That JSON result is basically the result of a query made to a custom backend, it could return information as simple as above, or there could be 50 columns, it depends on what query the user configures to run. Thus I can't configure the JSONReader in what appears to be the usual way as I don't know what the field names are going to be.

    I haven't been able to create the JSONReader though, I get an error when I attempt to construct it:

    Code:
    this.buildExtractors is not a function
    http://localhost:8080/AjaxTest/ext-3.0.3/ext-all-debug.js
    Line 32510
    I'm not sure what I'm doing wrong. This is what I've tried:

    Code:
    Ext.onReady(function  getResults() {
    
    	$.getJSON("SampleQueryResults",null,
    		function (data) {
    
    			var idProp;
    			if (data.headers.length > 0) {
    				idProp = data.headers[0].name;
    			}
    
    			//Create array of field mappings
    			var fields = new Array();
    			var columns = new Array();
    			for (var i=0; i<data.headers.length; i++) {
    				var field = new Ext.data.Field({
    					name: data.headers[i].name
    				});
    
    				fields[i] = field;
    
    
    
    				//I also tried with just a simple array of Strings, same error
    				//fields[i] = data.headers[i].name;
    
    			}
    
    			var myRecord = Ext.data.Record.create(fields);
    
    			var myReader = Ext.data.JsonReader({
    				idProperty: idProp,
    				root:"rows",
    				fields: myRecord
    			});
    		});
    });
    I also tried passing the array of fields directly in as the fields config in JsonReader, same error.

    When I examine the state in firebug it is clear that the object 'this' which looks like Ext.data.DataReader hasn't been created properly, but I'm unsure why. Is there some obvious error in what I'm doing?

    Cheers

  2. #2

    Default

    Quote Originally Posted by dpwrussell View Post
    Code:
    			var myReader = Ext.data.JsonReader({

    Cheers
    Thanks to PowerToExt in #extjs I found the schoolboy error:

    Code:
    			var myReader = new Ext.data.JsonReader({
    PowerToExt++

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •