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);
}
});
我正在尝试研究如何在s#中包装它。这是我尝试包装的确切内容
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 :(得分: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范式的强硬联合。打字框架。但是,我很想知道你是否能够实现以下目标:
(假设ExtDataProxyClient为[Import]
,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));
...
我怀疑你会遇到意想不到的行为,但我承认我没有深入研究Script#和ExtJS的输入infrustructure,以确定在这里。