2011-11-07 56 views
1

extjs使用間接類定義系統。這裏是腳本# - 需要包裝extjs函數的建議definiton

Ext.define('User', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     {name: 'name', type: 'string'}, 
     {name: 'age', type: 'int'}, 
     {name: 'phone', type: 'string'}, 
     {name: 'alive', type: 'boolean', defaultValue: true} 
    ], 

    changeName: function() { 
     var oldName = this.get('name'), 
      newName = oldName + " The Barbarian"; 

     this.set('name', newName); 
    } 
}); 

我試圖找出如何以s#這個包裹起來的例子。這裏是我tryiung確切的東西來包裝

Ext.define('jslate.data.Proxy', { 
    extend: 'Ext.data.proxy.Client', 
    constructor: function (config) { 
     this.callParent([config]); 

     //ensures that the reader has been instantiated properly 
     this.setReader(this.reader); 
     this.dataManager = config.dataManager; 
    }, 
    read: function (operation, callback, scope) { 
     var me = this; 
     me.dataManager.read(operation, callback, scope); 

    }, 

    clear: Ext.emptyFn 
}); 

我看不出如何做到這一點 - 有什麼建議?例如,我需要一個任意大小的函數名稱和定義數組,每個函數都有任意數量的參數。如果我在那裏得到'這個'。

回答

0

好了, 「1:1」 盲翻譯會是什麼樣子:

(假設你有[Import] ED類(ES)爲Ext.data.proxy.Client和Ext.emptyFn)

Ext.Define(
    "jslate.data.Proxy" 
    new Dictionary(
     "extend", "Ext.data.proxy.Client", 
     "constructor", new Action<Dictionary>(delegate(Dictionary config) { 
      Client self = (Client)Script.Literal("this"); 
      self.CallParent(new Object[] { config }); 

      self.SetReader(self.reader); 
      self.DataManager = config["dataManager"]; 
     }), 
     "read", new Action<Object, Action, Object>(delegate (Object operation, Action callback, Object scope) { 
      Client self = (Client)Script.Literal("this"); 
      self.DataManager.Read(operation, callback, scope); 
     }, 
     "clear", Ext.EmptyFn 
    ) 
); 

總體而言,這似乎是兩個不同的OOP範式&打字框架的強硬conjoining。不過,我很好奇,看看你能拉斷是這樣的:

(假設ExtDataProxyClient是[Import] ED和ICanInvokeParent定義CallParent()

class JslateDataProxy : ExtDataProxyClient, ICanInvokeParent 
{ 
    public JslateDataProxy(Config config) 
    { 
     this.CallParent(config); 
     this.SetReader(this.Reader); 
     this.DataManager = config.Datamanager; 
    } 

    public void Read(Object operation, Action callback, Object scope) 
    { 
     this.DataManager.Read(operation, callback, scope); 
    } 

    public Action Clear = Ext.EmptyFn; 
} 

static class Utils 
{ 
    public static void RegisterWithExt(Type t) 
    { 
     // extract fields, methods, constructor from type t. populate in a Dictionary(Object) 
     Dictionary typeSpecificationForDefine = ...; 

     // invoke define 
     Ext.Define(typeSpecificationForDefine); 
    } 
} 

... 

Utils.RegisterWithExt(typeof(JslateDataProxy)); 

... 

嫌疑你會碰到進入意想不到的行爲,但我承認我沒有深入研究腳本#和ExtJS的打字基礎知識,以便在這裏確定。

+0

優秀的答案 - tx。我們是否可以通過電子郵件聊天以跟進第二種方法(它與我正在嘗試做的事情相匹配)[email protected] – pm100