2012-04-20 2 views
0

json 파일을 목록에로드하려고합니다. 누구든지 내가 뭘 잘못하고 있는지 알 수 있니? 나는 아무런 오류가 없다.Sencha Touch에 json 파일을로드하려면 어떻게해야합니까?

Data.js :

Ext.regModel('Contact', { 
    fields: ['bandName', 'playDate'] 
}); 

ListDemo.ListStore = new Ext.data.Store({ 
    model: 'Contact', 
    sorters: 'bandName', 
    getGroupString : function(record) { 
     return record.get('bandName')[0]; 
    }, 

    /*data: [ 
     { bandName: "Bandname",  playDate: "Thursday 20:00" } 
    ]*/ 

    proxy: { 
     type: 'scripttag', 
     url: 'http://domain.com/artists.json', 
     reader : { 
      type : 'json', 
     }, 
     autoLoad: true 
    } 
}); 

하는 index.js :

ListDemo = 새로운 Ext.Application ({ 이름 : "ListDemo"

launch: function() { 

    ListDemo.detailPanel = new Ext.Panel({ 
     id: 'detailpanel', 
     tpl: 'Hello, {bandName}!', 
     dockedItems: [ 
      { 
       xtype: 'toolbar', 
       items: [{ 
        text: 'back', 
        ui: 'back', 
        handler: function() { 
         ListDemo.Viewport.setActiveItem('disclosurelist', {type:'slide', direction:'right'}); 
        } 
       }] 
      } 
     ] 
    }); 

    ListDemo.listPanel = new Ext.List({ 
     id: 'disclosurelist', 
     store: ListDemo.ListStore, 
     itemTpl: '<div class="contact">{bandName}<br /><span style="font-size:12px;">{playDate}</span></div>', 
     grouped: true, 
     onItemDisclosure: function(record, btn, index) { 
      ListDemo.detailPanel.update(record.data); 
      ListDemo.Viewport.setActiveItem('detailpanel'); 
     } 
    }); 

    ListDemo.Viewport = new Ext.Panel ({ 
     fullscreen: true, 
     layout: 'card', 
     cardSwitchAnimation: 'slide', 
     items: [ListDemo.listPanel, ListDemo.detailPanel] 
    }); 

} 
}); 

내 JSON 파일 :

[ 
    { "id": 1, "bandName": "Moe", "playDate": "Thursday" }, 
    { "id": 2, "bandName": "Larry", "playDate": "Thursday" }, 
    { "id": 3, "bandName": "Curly", "playDate": "Thursday" }  
] 

내가 뭘 잘못하고 있는지 누가 알 수 있니?

답변

0

JSON 파일이 배열 형식입니다. 이 배열이있는 노드를 값으로 추가 한 다음 Sencha Touch 파일의 데이터 노드 (프록시)를이 노드로 설정합니다. 다음과 같이 json으로 보일 것입니다 : 당신은 당신의 코드를 디버깅하는 크롬의 검색 및 Chrome 개발자 도구를 사용한다

"data": [ 
    { "id": 1, "bandName": "Moe", "playDate": "Thursday" }, 
    { "id": 2, "bandName": "Larry", "playDate": "Thursday" }, 
    { "id": 3, "bandName": "Curly", "playDate": "Thursday" }  
] 
+0

안녕하세요, 저는 json이 처음입니다. 어떻게 만들 수 있습니까? – Elias

+0

편집을 참조하십시오. – Geerten

0

. 당신의 json 파일이 맞습니다.

+0

Sencha Touch에서 이해할 수 있도록 올바른 JSON이지만 맞습니까? 그들은 정확하게 구조를 분석해야합니다. – Geerten

+0

Sencha Touch 예제에서 json 파일을 참조 할 수 있습니다. –

관련 문제