在ExtJS中将静态属性值传递给类定义时,无法读取未定义的属性



我想知道是否有人能为我在ExtJS 4中遇到的一个特殊问题提供一些帮助。我定义了一个存储区,它从一个类中获取我在代理中api对象的"读取"one_answers"创建"属性中指定的一些值,这些值在该类的statics部分中定义。然而,当我运行应用程序时,我不断收到错误:

**Uncaught TypeError: Cannot read property 'Url' of undefined**.

这是商店

Ext.define('MyApp.store.address.AddressStore',
{
extend: 'Ext.data.Store',
model: 'MyApp.model.address.AddressModel',
requires: ['MyApp.props.Url'],
proxy: {
type: 'ajax',
api: {
create: MyApp.props.Url.Address.ADD_ADDRESS_URL, //This is defined in the static class below
read: MyApp.props.Url.Address.GET_ALL_ADDRESSES_URL //As is this
},
reader: {
type: 'json',
root: 'Addresses'
}
}
}
);

这是定义静态属性MyApp.props.Url 的类

Ext.define('MyApp.props.Url', {
statics: {
Address: {
ADD_ADDRESS_URL: 'Address/AddAddress',
GET_ALL_ADDRESSES_URL: 'Address/GetAllAddresses',
GET_ALL_ADDRESS_TYPES_URL: 'Address/GetAllAddressTypes'
}
}

});

考虑一下代码的求值顺序。在这种情况下,你本质上是在说:

Ext.define('MyClassName', o);

只有在解析完整个对象后,类定义才会传递给define。这意味着只有当我们进入define调用时,才会处理需求。

你需要做一些类似的事情:

Ext.require('MyApp.props.Url', function() {
console.log(MyApp.props.Url.Address.ADD_ADDRESS_URL);
Ext.define('MyClass', {});
});

最新更新