2011-03-16 119 views
1

我有一个存储在列表中携带数据的问题,事情是商店正在执行该负载,但列表保留在加载中,我做错了什么,谢谢Sencha与json商店的触摸列表

Ext.regModel('Properties', { 
      fields: [ 
       {name: 'idcounty', type: 'string'}, 
       {name: 'county', type: 'string'} 
      ] 
     }); 

     store = new Ext.data.Store({ 
      model : 'Properties', 
      proxy: { 
       type: 'ajax', 
       url: 'php/response_grid.php?module=countys', 
       reader: { 
        type: 'json', 
        root: 'results', 
        totalCount: 'total' 
       } 
      }, 
      autoLoad:true 
     }); 
var listPanel = { 
      dockedItems: [ 
       { 
        title: 'Results', 
        xtype: 'toolbar', 
        ui: 'light', 
        dock: 'top' 
       } 
      ], 
      layout: 'fit', 
      scroll: 'vertical', 
      items: [ 
       { 
        xtype: 'list', 
        itemTpl : '{county}', 
        store: store, 
        singleSelect: true, 
        onItemDisclosure: function(record, btn, index){ 

        } 
       } 
      ], 
      flex:1 
     }; 

,并从PHP

({"total":"67","results":[{"idcounty":"1","county":"Broward"},{"idcounty":"2","county":"Dade"},{"idcounty":"3","county":"Palm Beach"},{"idcounty":"4","county":"Osceola"},{"idcounty":"5","county":"Lake"},{"idcounty":"6","county":"Orange"},{"idcounty":"7","county":"Seminole"},{"idcounty":"8","county":"Volusia"},{"idcounty":"9","county":"Hillsborough"},{"idcounty":"10","county":"Polk"},{"idcounty":"11","county":"Pasco"},{"idcounty":"12","county":"Pinellas"},{"idcounty":"13","county":"Sarasota"},{"idcounty":"14","county":"Manatee"},{"idcounty":"15","county":"Charlotte"},{"idcounty":"16","county":"Alachua"},{"idcounty":"17","county":"Baker"},{"idcounty":"18","county":"Bay"},{"idcounty":"19","county":"Bradford"},{"idcounty":"20","county":"Brevard"},{"idcounty":"21","county":"Calhoun"},{"idcounty":"22","county":"Citrus"},{"idcounty":"23","county":"Clay"},{"idcounty":"24","county":"Collier"},{"idcounty":"25","county":"Columbia"},{"idcounty":"34","county":"Duval"},{"idcounty":"35","county":"Escambia"},{"idcounty":"36","county":"Flagler"},{"idcounty":"37","county":"Franklin"},{"idcounty":"38","county":"Gadsden"},{"idcounty":"39","county":"Gilchrist"},{"idcounty":"40","county":"Glades"},{"idcounty":"41","county":"Gulf"},{"idcounty":"42","county":"Hamilton"},{"idcounty":"43","county":"Hardee"},{"idcounty":"44","county":"Hendry"},{"idcounty":"45","county":"Hernando"},{"idcounty":"46","county":"Highlands"},{"idcounty":"47","county":"Holmes"},{"idcounty":"48","county":"Jackson"},{"idcounty":"49","county":"Jefferson"},{"idcounty":"50","county":"Lafayette"},{"idcounty":"52","county":"Lee"},{"idcounty":"53","county":"Leon"},{"idcounty":"54","county":"Levy"},{"idcounty":"55","county":"Liberty"},{"idcounty":"56","county":"Madison"},{"idcounty":"58","county":"Martin"},{"idcounty":"59","county":"Monroe"},{"idcounty":"60","county":"Nassau"},{"idcounty":"61","county":"Okaloosa"},{"idcounty":"62","county":"Okeechobee"},{"idcounty":"63","county":"Putnam"},{"idcounty":"64","county":"Sumter"},{"idcounty":"65","county":"Taylor"},{"idcounty":"66","county":"Union"},{"idcounty":"67","county":"Wakulla"},{"idcounty":"68","county":"Walton"},{"idcounty":"69","county":"Washington"},{"idcounty":"70","county":"DeSoto"},{"idcounty":"71","county":"IndianRiver"},{"idcounty":"72","county":"SantaRosa"},{"idcounty":"75","county":"St Johns"},{"idcounty":"77","county":"St Lucie"},{"idcounty":"78","county":"Dixie"},{"idcounty":"80","county":"Suwannee"},{"idcounty":"81","county":"Marion"}]}) 
+2

palenthesis at the服务器的json输出 - “(”和“)” - 必须删除才能正确加载数据。 –

回答

5

我得到了你的榜样工作,但我不得不改变一些东西,我把它包在一个应用程序只是为了得到工作的JSON答案。具体来说,我必须在应用程序后移动模型,以便商店可用。

在上面的例子中,你只是做:

store = new Ext.data.Store({...

我认为你需要做的:

var stor = new Ext.data.Store({...

反正这里是我工作的代码,让您的数据是好的...

Ext.ns("Test", "Test.stores"); 


Test = new Ext.Application({ 
    defaultTarget : 'viewport', 
    name : 'test', 
    icon : 'icon.png', 
    glossOnIcon : false, 
    tabletStartupScreen : 'tablet_startup.png', 
    phoneStartupScreen : 'phone_startup.png', 
    launch : function() { 
    console.log('begin'); 

    this.viewport = new Ext.Panel({ 
     fullscreen : true, 
     dockedItems : [ { 
     title : 'Results', 
     xtype : 'toolbar', 
     ui : 'light', 
     dock : 'top' 
     } ], 
     layout : 'fit', 
     scroll : 'vertical', 
     items : [ { 
     xtype : 'list', 
     itemTpl : '<span id="{idcounty}">{county}</span>', 
     store : Test.stores.Properties, 
     singleSelect : true, 
     itemSelector : 'span.id', 
     onItemDisclosure : function(record, btn, index) { 

     } 
     } ], 
     flex : 1 
    }); 

    } 
}); 

Ext.regModel('Properties', { 
    fields : [ { 
    name : 'idcounty', 
    type : 'string' 
    }, { 
    name : 'county', 
    type : 'string' 
    } ] 
}); 

Test.stores.Properties = new Ext.data.Store({ 
    model : 'Properties', 
    proxy : { 
    type : 'ajax', 
    url : 'test.json', 
    reader : { 
     type : 'json', 
     root : 'results', 
     totalCount : 'total' 
    } 
    }, 
    autoLoad : true 
}); 
+0

谢谢,我会试试你的解决方案 – juandej18