2012-07-11 26 views
0

目前,我正在學習煎茶觸摸和作爲一個測試,我寫了一個小的web服務,我想在列表中顯示煎茶觸摸和PHP的Webservice

產生的項目,但我不能得到它的工作.. 。

Ext.define('GS.view.ListTest', { 
    extend: 'Ext.navigation.View', 

    requires:[ 
     'Ext.dataview.List', 
     'Ext.data.proxy.JsonP', 
     'Ext.data.Store' 
    ], 
    xtype:'listpanel', 
    config: { 
     title: 'Fifa List', 
     iconCls: 'star', 

     items: { 
      xtype: 'list', 
      itemTpl: '{Player1}', 

      store: { 
       autoLoad: true, 
       fields: ['MatchID','Player1', 'ScorePlayer1' ,'ScorePlayer2','Player2'], 

       proxy: { 
        type: 'jsonp', 
        url: 'http://fifa.verhulstrobin.be/webservices/getMatches.php', 
        reader: { 
         type:'json', 
         rootProperty: 'matches' 
        } 
       } 
      } 

     } 

    } 
}); 

我檢查,我的JSON是有效的... 所有它說,在控制檯是未捕獲的SyntaxError:意外的標記:

+0

您正在使用JSONP代理的任何特定reaxon?你不能只使用Ajax代理嗎? – 2012-07-12 20:39:44

回答

0

試試這個

items: { 
    xtype: 'list', 
    itemTpl: '{match.Player1}', 

    store:new Ext.create('Ext.data.Store', { 
     autoLoad: true, 
     fields: ['match'], 

     proxy: { 
      type: 'jsonp', 
      url: 'http://fifa.verhulstrobin.be/webservices/getMatches.php', 
      reader: { 
       type:'json', 
       rootProperty: 'matches' 
      } 
     }) 
    } 
} 
+0

新的Ext.create(...)??? – 2012-07-11 12:58:08

+0

http://stackoverflow.com/questions/11209398/sencha-touch-2-store-typeerror/11209631#11209631 referr這個答案 – 2012-07-11 13:00:02

+0

這是一個泄氣的方法 – drew630 2012-07-12 01:17:12

0

嘗試這樣的事情,而不是:

items: { 
     xtype: 'list', 
     itemTpl: '{match.Player1}', 

     store: { 
      autoLoad: true, 
      fields: ['match'], 

      proxy: { 
       type: 'jsonp', 
       url: 'http://fifa.verhulstrobin.be/webservices/getMatches.php', 
       reader: { 
        type:'json', 
        rootProperty: 'matches' 
       } 
      } 
     } 
    } 

希望這有助於

+0

仍然返回相同的錯誤,無論如何感謝 – SnK 2012-07-11 11:33:54

+0

好的,我會試一下 – 2012-07-11 12:58:37

0

在你的web服務響應的樣子,我注意到,它不換行的JSON答案在函數調用像JSONP需要。你需要返回一個項目是這樣的:

Ext.data.JsonP.callback1({}); 

其中,函數的參數必須是實際的JSON數據,而不是一個空的對象,函數「Ext.data.JsonP.callback1」的名字作爲參數由Ext Store傳遞給您的webservice,名稱爲「callback」。

但是,您可以自定義參數的名稱與callbackKey對代理:

var store = Ext.create('Ext.data.Store', { 
    model: 'User', 
    proxy: { 
     type: 'jsonp', 
     url : 'http://domainB.com/users', 
     callbackKey: 'theCallbackFunction' // <-- 
    } 
}); 

有關詳細信息JSONP以及如何實現它的Ext JS的商店,你可以參考http://en.wikipedia.org/wiki/JSONPhttp://docs.sencha.com/touch/2-0/#!/api/Ext.data.proxy.JsonP