2011-11-07 4 views
1

extjsは間接クラス定義システムを使用しています。ここに例がありますスクリプト# - extjs関数をラップするための提案が必要です。

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); 
    } 
}); 

私はこれを#で包む方法を工夫しています。ここでは、私はラップするために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" 盲目の翻訳は次のようになります。

(あなたがExt.data.proxy.ClientとExt.emptyFnため [Import] EDクラス(複数可)を持っていると仮定)
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のように思えます。私はあなたが実行されます容疑者

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)); 

... 

(ExtDataProxyClientが[Import]編で、ICanInvokeParentCallParent()を定義すると仮定した場合)

:しかし、私はあなたのような何かをやってのけることができるかどうかを確認するために好奇心があると思いこれを行う予期しない振る舞いになってしまいましたが、私はScript#とExtJSのタイプインストラクチャを深く掘り下げていないことを認めています。

+0

優れた回答 - 私たちはあなたの2番目の方法(それは私がやろうとしていたものと一致しています)をフォローアップするために電子メールで少しチャットできますか?[email protected] – pm100

関連する問題