【解決方法】外部 URL を持つ EXT JS ストア

プログラミングQA


皆さん、

グリッドを使用して EXT JS プロジェクトを構築しています。 そのストアは次のように定義されています。

JavaScript
createStore     :  function() {
       var me = this;
       me.createDataModel();
       var store = Ext.create("Ext.data.Store", {
           model       :  "tescoModel",
           id          :  "tescoStore",
           autoLoad    :  true,
           remoteSort  :  true,
           pageSize    :  20,
           proxy       :  {
               type            : "ajax",
               url             : "http://www.techfortesco.com/groceryapi_b1/restservice.aspx",
               limitParam      : undefined,
               startParam      : undefined,
               simpleSortMode  : true,
               pageParam       : undefined,
               noCache         : false,
               actionMethods   : {
                   method  : "POST"
               },
               reader           : {
                   type            : "json",
                   root            : "Products",
                   totalProperty   : "TotalProductCount"
               }
          }
       });

ただし、これはまったく何も返しません。http://www.techfortesco.com への接続さえ確立しません。
extjs は内部リンク (/techfortesco など) への接続のみを許可していると思います。

extjs が外部リンクからストアを作成することは可能ですか? 私は何か間違ったことをしていますか?

ありがとう

解決策 1

Proxy Type を ‘jsonp’ として使用する必要があります

JavaScript
createStore     :  function() {
       var me = this;
       me.createDataModel();
       var store = Ext.create("Ext.data.Store", {
           model       :  "tescoModel",
           id          :  "tescoStore",
           autoLoad    :  true,
           remoteSort  :  true,
           pageSize    :  20,
           proxy       :  {
               type            : "jsonp",
               url             : "http://www.techfortesco.com/groceryapi_b1/restservice.aspx",
               limitParam      : undefined,
               startParam      : undefined,
               simpleSortMode  : true,
               pageParam       : undefined,
               noCache         : false,
               actionMethods   : {
                   method  : "POST"
               },
               reader           : {
                   type            : "json",
                   root            : "Products",
                   totalProperty   : "TotalProductCount"
               }
          }
       });

解決策 2

EXTJS の Loader 機能を試す –

loader: {
	    url: 'YourSourceUrl',
            renderer: 'component',
            autoLoad: true
	}

autoload: true、初期ロード時にデータを自動的にロードします。

コメント

タイトルとURLをコピーしました