2011-11-07 97 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