2

我的json格式

 Ext.data.JsonP.callback3({"nodes":[
 {"node":{"title":"Dane Sample Name - Owner/Stylist/Daymaker","field_headshot":"","body":"Born and raised in Carencro, La., Dane knew from a young age that he wanted to become a successful hairdresser. \n","nothing":""}},

 {"node":{"title":"Rahul - Owner/Stylist/Daymaker","field_headshot":"","body":"Since 1995 Jeanne has enjoyed helping people to feel and look beautiful.\n","nothing":""}}]})

楷模

Ext.define('SampleApp.model.Drupal', {
extend: 'Ext.data.Model',
 uses: [
    'SampleApp.model.Drupal2'
],
config: {
        fields : [ 
            'node'
        ],

},   
 hasMany: {
         model: 'Drupal2',
         name  : 'node',
         associationKey: 'node' ,
      }    
 });

Ext.define('SampleApp.model.Drupal2', {
    extend: 'Ext.data.Model',


    config: {
        fields: [
            'title','body'
        ]}     
});

店铺

Ext.define('SampleApp.store.DrupalStore', {
extend: 'Ext.data.Store',
requires: [ 
    'SampleApp.model.Drupal2'],

config: {
    autoLoad : true,
    model: 'SampleApp.model.Drupal2',
    proxy: {
        type: 'jsonp',
        url: 'data/data.json',
        reader: {
            type: 'json',
            rootProperty: 'nodes.node'
        }
    }
}
});   

以上是来自drupal视图的嵌套json,我正在尝试使用这两个模型并存储在我的视图中加载列表。我正在尝试从节点添加标题列表,但列表未加载到视图中。如果我给root属性作为节点然后它正在加载所有数据但不映射到节点。请帮助我解决我哪里出错了。

4

1 回答 1

0

更改了我的模型,它没有使用关联。这是对我有用的模型

 Ext.define('SampleApp.model.Drupal', {
 extend: 'Ext.data.Model',
   config: {
        fields: [
              {
            name: 'title',
            mapping: 'node.title', // mapping worked

        },
        {
            name: 'field_headshot',
            mapping : 'node.field_headshot',

        },
        {
            name: 'body',
            mapping : 'node.body',
        }
        ],
    }
 });
于 2013-10-29T16:35:04.660 回答