Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
16
rated 0 times [  21] [ 5]  / answers: 1 / hits: 8441  / 11 Years ago, tue, february 25, 2014, 12:00:00

I was was wondering whether someone could give some help with a peculiar problem that I am having in ExtJS 4. I have a defined a store that takes some of the values that I have specified in the 'read' and 'create' properties of the api object in the proxy from a class where these values are defined in the statics section of the class. However, when I run the app, I keep getting the error:



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



Here is the store



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'
}
}
}

);


Heres is the the class that defines the static properties 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'
}
}


});


More From » extjs

 Answers
3

Think about the evaluation order of the code. In this case, you're essentially saying:



Ext.define('MyClassName', o);



The class definition only gets passed to define once the whole object is resolved. This means that the requires are only processed once we get inside the define call.



You need to do something like:



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

[#47408] Tuesday, February 25, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
analiseg

Total Points: 460
Total Questions: 96
Total Answers: 90

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
;