Question

I am a beginner to sencha Touch, basically i am a blackberry developer. Currently we are migrating our application to support Sencha Touch 1.1. Now i have some business solutions like i want to store the selected values in the local database. I mean i have multiple screens where, Once the user selects a value in each of the screen the data should save in the below following format.

[{'key1': "value1", 'key2': "value2", 'key3': "value3" ,'key4': "value4", 'key5': "value5"}]

1. First, the values need to be saved in key value pairs

2. The keys should play the role of primary key, key shouldn't be duplicated.

3. Should be available till the application life cycle or application session, don't need to save the data permanently.

I have come across the concepts like LocalStorageProxy, JsonStore and some others. I don't understand which one i can use for my specific requirements.

May be my question is bit more confusing. I have achieved the same using vector, in Blackberry Java so any data structure similar to this could help me. Need the basic operations like

  1. Create
  2. Add
  3. Remove
  4. Remove all
  5. Fetch elements based on key

Please suggest me some samples or some code snapshots, which may help me to achieve this.

Edit: 1

I have done the changes as per @Ilya139 's answer. Now I am able to add the data with key,

// this is my Object declared in App.js
NSDictionary: {},

// adding the data to object with key
MyApp.NSDictionary['PROD'] = 'SONY JUKE BOX';

//trying to retrieve the elements from vector 
var prod = MyApp.NSDictionary['PROD'];

Nut not able to retrieve the elements using the above syntax.

Was it helpful?

Solution

If you don't need to save the data permanently then you can just have a global object with the properties you need. First define the object like this:

 new Ext.Application({
    name: 'MyApp',
    vectorYouNeed: {},
   launch: function () { ...

Then add the key-value pairs to the object like this

 MyApp.vectorYouNeed[key] = value;

And fetch them like this

 value = MyApp.vectorYouNeed[key];

Note that key is a string object i.e. var key='key1'; and value can be any type of object.

To remove one value MyApp.vectorYouNeed[key] = null; And to remove all of them MyApp.vectorYouNeed = {};

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top