2012-05-10 98 views
2

我無法在我的視圖中顯示列表。看來我從我的ajax調用中獲取數據。 我絕對錯過了這裏的東西。請幫忙。由於列表不顯示

以下是詳細信息: 數據:

Stations.json

[ 
{ 
    "id": "129", 
    "stop": "NY Station", 
}, 
{ 
    "id": "13", 
    "stop": "Newark Station", 
} 

] 

型號:

Ext.define('MyApp.model.Station', { 
extend: 'Ext.data.Model', 

config: { 
    fields: [ 
     {name: 'id', type: 'string'}, 
    {name: 'stop', type: 'string'} 

    ] 
} 

}); 

商店:

 
     Ext.define('MyApp.store.Stations', { 
     extend : 'Ext.data.Store', 
     requires: ['MyApp.model.Station'], 
    id: 'stations', 
    xtype: 'stations', 
    config : { 
     model : 'MyApp.model.Station', 
     storeId: 'stationsStore', 
     autoLoad : true, 
     //sorters: 'stop', 
     proxy: { 
       type: 'ajax', 
       url: 'Stations.json' 

    } 
    }); 

查看:

Ext.define('MyApp.view.MyService', { 
extend: 'Ext.Panel', 
xtype: 'stationsformPage', 
fullscreen: true, 
layout: 'vbox', 
requires: [ 
    'MyApp.store.Stations',  
    'Ext.form.FieldSet', 
    'Ext.field.Password', 
    'Ext.SegmentedButton', 
    'Ext.List' 
    ], 

config: { 
    iconCls: 'settings', 
    title: 'My Service', 
    items: [ 
     { 
      docked: 'top', 
      xtype: 'toolbar', 
      title: 'My Service' 
     }, 

     { 
      xtype: 'list', 
      title: 'Stations', 
      store: 'stationsStore', 
      styleHtmlContent: true, 
      itemTpl: '<div><strong>{stop}</strong> {id}</div>' 

     }, 

    ] 
    }, 
    initialize: function() { 

     /* 
     Ext.Ajax.request({ 
      scope : this, 
      url: 'StationLocator.json', 
      callback : function(options, success, response){ 
        var json = Ext.decode(response.responseText); 
        alert(response.responseText); //this works 
        alert(json[0].stop); //this works 
      } 
     }); 
     */ 

    }//initialize 

    }); 

回答

2

我把它放在TabPanel中。這會有幫助嗎?它看起來像這樣:

enter image description here

這是我的觀點:

 
Ext.define('MyApp.view.MyService', { 
    extend: 'Ext.tab.Panel', 
    xtype: 'stationsformPage', 
    fullscreen: true, 
    layout: { 
     pack: 'center' 
    }, 
    requires: [ 
     'MyApp.store.Stations', 
     'Ext.form.FieldSet', 
     'Ext.field.Password', 
     'Ext.SegmentedButton', 
     'Ext.List' 
    ], 
    config: { 
     tabBarPosition:'bottom', 
     layout: { 
      type: 'card', 
      animation: { 
       duration: 300, 
       easing: 'ease-in-out', 
       type: 'slide', 
       direction: 'left' 
      } 
     }, 
     fullscreen: true, 
     title: 'My Service', 
     items: [ 
      { 
       docked: 'top', 
       xtype: 'toolbar', 
       title: 'My Service' 
      }, 

      { 
       xtype: 'list', 
       title: 'Stations', 
       store: 'stationsStore', 
//    height: 600, 
//    width: 400, 
//    style: 'background-color: #c9c9c9;', 
       styleHtmlContent: true, 
       itemTpl: '{stop} {id}' 

      } 

     ] 
    } 

}); 




下面是放在一個普通面板列表中的一個版本:

enter image description here

 
Ext.define('MyApp.view.MyService', { 
    extend: 'Ext.Panel', 
    xtype: 'stationsformPage', 
    fullscreen: true, 
    layout: { 
     pack: 'center' 
    }, 
    requires: [ 
     'MyApp.store.Stations', 
     'Ext.form.FieldSet', 
     'Ext.field.Password', 
     'Ext.SegmentedButton', 
     'Ext.List' 
    ], 
    config: { 

     fullscreen: true, 
    layout: 'fit', // Specifying fit is important. Won't see list without it 
     title: 'My Service', 
     items: [ 
      { 
       docked: 'top', 
       xtype: 'toolbar', 
       title: 'My Service' 
      }, 

      { 
       xtype: 'list', 
       store: 'stationsStore', 

       styleHtmlContent: true, 
       itemTpl: '{stop} {id}' 

      } 
     ] 
    } 
}); 
+0

非常感謝它的工作。但爲什麼在Panel或Form Panel中不可能? – AbbIbb

+1

我添加了面板解決方案。如果你沒有看到任何東西,它有時可以幫助給出一個幫助調試的高度。有時候視圖崩潰,你看起來不可能。 – 2012-05-15 16:46:19

+0

@ user568866非常感謝!我遇到了同樣的問題,「佈局:」合適「」部分是問題! – CodeCanuck