简体   繁体   中英

How to read values from properties file in ExtJs

I want to read values from config.properties and use these values in my ExtJs ComboBox . I do not want to read from JSON file.

Where should I place the config.properties file? Should I place it in the webcontent directly? I do not want to hard code the path/ or at least reduce it.

And how can I access property values through JavaScript.?

Thanks

This is not ExtJS specific but in general rather applicable to javascript as a whole.

Best bet would be to either include it in a global file that gets included in your app and is namespaced appropriately to your app so as to minimise chance of collisions with any other potential variables

 MyApp = { config:{ property1:'something', property2:'something2' } } // Then you can access this anywhere you like myProperty1 = MyApp.config.property1; // assigns the string "something" to variable myProperty1 

You can load the properties file into a data store, this way you can have the key-value pairs in the your properties file mapped to a simple model with fields key and value. And to enable your proxy to load data from the properties file and be converted into the corresponding model you'll have to create a reader that'll read the data from the properties file and convert to the desired record.

This custom package for i18n will give you some idea how to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM