English 中文(简体)
ExtJS 4 Beta 3 Model Won t Load Data From JSON File
原标题:

The model:

Ext.ns( Workout.Models.user );
Ext.regModel( User , {
    fields: [{
        name:  member_id ,
        type:  int 
    }, {
        name:  first_name ,
        type:  string 
    }, {
        name:  last_name ,
        type:  string 
    }, {
        name:  username ,
        type:  string 
    }, {
        name:  password ,
        type:  string 
    }, {
        name:  dob ,
        type:  date ,
        dateFormat:  Y-m-d 
    }, {
        name:  email_address ,
        type:  string 
    }, {
        name:  is_active ,
        type:  int 
    }],
    proxy: {
        type:  ajax ,
        format:  json ,
        url:  ../../_dev/json_fixtures/users.json ,
        reader: {
            type:  json ,
            root:  users 
        },
        root:  users 
    }
});

The Store:

Ext.ns( Workout.Stores );
Workout.Stores.user = new Ext.data.Store({
    model:  User ,
    storeId :  Workout.Stores.user ,
    sorters: [
         last_name ,
         first_name ,
         member_id 
    ],
    autoLoad: true
});

The Grid:

Ext.ns( Workout.User );
Workout.User.grid = new Ext.grid.Panel({
    store:  Workout.Stores.user ,
    columns:[{
        text:  Created At ,
        dataIndex:  created_at 
    }, {
        text:  First Name ,
        dataIndex:  first_name 
    }]
});

The JSON File

{
    "users":[{
        "created_at":"2011-04-01 14:13:34",
        "member_id":"14453",
        "first_name":"Jemima",
        "last_name":"Petersen",
        "username":"jpeterson",
        "password":"TDW29HOH7WY",
        "dob":"1960-07-03",
        "email_address":"at.velit.Pellentesque@sociis.com"
    }]
}

Wheh I load my HTML page, the grid is empty. However, if I supply raw data to the store via the data param, it loads. If I call User.load() manually via the console, nothing happens. If i call User.load() and pass in a valid JSON object,nothing happens.

Is there something I m missing / not doing right?

最佳回答

You have done everything expect set the height of your grid panel. You need to set the height to display the records. Here is what I would add to your grid panel config:

height: 300

Now, apart from this, you have other problems like you have not defined created_at in your User model. If you plan to display the value in your grid, you need to update your model as well.

问题回答
Ext.define(
 BK.store.Categories 
,   {       extend      :    Ext.data.Store 
        ,   model       :    BK.model.Category  
        ,   autoload    :   true
        ,   proxy       :   {       type    :    ajax 
                                ,   format  :    json 
                                ,   root    :    results 
                                ,   api     :   {   read    :    data/data1.json    }

                                ,   reader  :   new Ext.data.JsonReader({       type            :    json 
                                                    ,   root            :    results 
                                                    ,   successProperty :    success 
                                                    })
                            }
    }

);

when I use data hardcoded in the store, it works OK (so model, view, controller are OK), as soon as I use the proxy it behaves as if autoload were FALSE, no net request





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签