2013-08-05 23 views
1

下面,您將看到我得到一個JavaScript異常,並在Sencha ExtJS MVC應用程序中創建了一個MVC視圖。我有另一個MVC視圖,它擴展了'Ext.tree.Panel',它讀​​取一個簡單的JSON對象,而不是通過Ext.Direct代理和.NET服務器端堆棧提取數據,但唯一不同的是代理實現和當然我們的MVC控制器邏輯。在靜態(JSON)實現中,我們的代理是在模型中定義的。在動態(Ext.Direct)實現中,我們的代理在商店中定義。在瀏覽器崩潰之前,TreeStructures.js(store)JavaScript文件會一直被請求無數次。請參閱下面的例外。同步加載'MyApp.store.TreeStructures';考慮在Ext.onReady之上添加Ext.require('MyApp.store.TreeStructures')

我非常懷疑這是一個Ext.Direct問題,因爲我有其他商店在這個體系結構很好的工作。我看到[Ext.Loader]異常,但我不確定爲什麼那個人不斷重複每一個新的TreeStructures.js請求。或者在哪裏實施。我的理解是,app.js定義了控制器。控制器然後將模型定義爲商店。而視口定義並實例化其他MVC視圖。我的「其他觀點」是樹形圖。視圖實現商店。

此外,Sencha Cmd「sencha應用程序構建」命令不起作用。通常我的應用程序編譯沒有任何問題,所以在此動態樹中必需的商店或MVC配置中肯定缺少一些東西。

異常在JavaScript控制檯:

[Ext.Loader] Synchronously loading 'MyApp.store.TreeStructures'; consider adding Ext.require('MyApp.store.TreeStructures') above Ext.onReady 

Browser這個JavaScript異常崩潰:

注:JavaScript文件不斷被請求的次數無限量,直至該TreeStructures.js(存儲)瀏覽器與此崩潰了:

Uncaught RangeError: Maximum call stack size exceeded 

個煎茶Cmd的錯誤(調用「煎茶應用程序構建」命令後):

[ERR] failed to find meta class definition for name MyApp.store.TreeStructures 
[ERR] def was null 
[ERR] C2008: Requirement had no matching files <MyApp.store.TreeStructures> -- unknown-file:-1 

靜態樹的實現(讀取JSON對象,以獲取數據):

Ext.define('MyApp.store.Categories', { 
    extend : 'Ext.data.TreeStore', 
    model : 'MyApp.model.Category', 
    autoLoad : true, 
    root : { 
     text : 'All', 
     alias : '', 
     expanded : true 
    } 
}); 

Ext.define('MyApp.model.Category', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     { name: 'alias', type: 'auto' }, 
     { name: 'text', type: 'auto' } 
    ], 

    proxy: { 
     type: 'ajax', 
     url: 'data/categories.json' 
    } 
}); 

Ext.define('MyApp.controller.ConceptTreeReadonly', { 
    extend : 'Ext.app.Controller', 
    stores: ['Categories'], 
    models: ['Category'], 
    refs : [{ 
     ref: 'categories', 
     selector: 'view-west' 
    }], 
}); 

動態樹的實現(使用服務器端堆棧獲取數據):

Ext.create('MyApp.store.TreeStructures', { 
    extend: 'Ext.data.TreeStore', 
    model : 'MyApp.model.TreeStructure', 
    proxy: { 
     type: 'direct', 
     directFn: Concept_Tree_Structure.read, 
     reader: { 
      root: 'data' 
     } 
    }, 
    root: { 
     text: 'Concept Tree', 
     id: 'root', 
     expanded: false 
     //children: [] 
    }, 
    autoLoad: false 
}); 

Ext.define('MyApp.model.TreeStructure', { 
    extend: 'Ext.data.Model', 
    xtype: 'model-tree-structure', 

    fields: [ 
     { name: 'text' }, // string      
     { name: 'id' }, // Int32 type: 'int' 
     { name: 'expanded' }, // boolean     
     { name: 'leaf' }, // boolean  
     { name: 'children' } // List<TreeStructure>    
    ] 
}); 

Ext.define('MyApp.controller.ConceptTreeController', { 
    extend : 'Ext.app.Controller', 

    stores: ['TreeStructures', 'Concepts'], 
    models: ['TreeStructure', 'Concept'], 

    refs : [{ 
     ref: 'concept-tree', 
     selector: 'view-concept-tree' 
    }], 
    init : function() { 

     this.getConceptsStore().load({ 
      params: { 
       start: 0, 
       limit: 10, 
       foo: 'bar' 
      } 
     }); 

     this.getTreeStructuresStore().load({ 
      params: { 
       start: 0, 
       limit: 10, 
       foo: 'bar' 
      } 
     }); 
    } 
}); 
+1

看起來像它,因爲你在你的TreeStructures商店做了Ext.create而不是Ext.define。 – bakamike

+0

隨意做出這個答案。你是一個拯救生命的人。我想我只是需要一些睡眠! – MacGyver

+0

爲了記錄,[requirejs](http://requirejs.org/)是專門處理動態文件包含的另一個庫。除了底層概念之外,它與ExtJS無關。 – rixo

回答

5

變化Ext.create( 'MyApp.store.TreeStructures' ......

To Ext.define('MyApp.store.TreeStructures'...