在Sencha Touch中使用的数据结构类似于Blackberry中的Vector

时间:2022-06-28 18:25:16

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.

我是sencha Touch的初学者,基本上我是黑莓开发者。目前我们正在迁移我们的应用程序以支持Sencha Touch 1.1。现在我有一些业务解决方案,比如我想将所选值存储在本地数据库中。我的意思是我有多个屏幕,一旦用户在每个屏幕中选择一个值,数据应该以下面的格式保存。

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

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

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

1.首先,需要将值保存在键值对中

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

2.密钥应起主键作用,密钥不应重复。

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

3.应该可以在应用程序生命周期或应用程序会话期间使用,不需要永久保存数据。

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.

我遇到过像LocalStorageProxy,JsonStore和其他一些概念。我不明白哪个可以用于我的具体要求。

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

可能是我的问题有点混乱。我在Blackberry Java中实现了相同的使用向量,因此任何与此类似的数据结构都可以帮助我。需要像。这样的基本操作

  1. Create
  2. 创建
  3. Add
  4. Remove
  5. 去掉
  6. Remove all
  7. 移除所有
  8. Fetch elements based on key
  9. 根据键获取元素

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

请给我一些示例或一些代码快照,这可能有助于我实现这一目标。

Edit: 1

编辑:1

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

我按照@ Ilya139的回答做了改动。现在我可以使用密钥添加数据,

// 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.

Nut无法使用上述语法检索元素。

1 个解决方案

#1


1  

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.

注意,key是一个字符串对象,即var key ='key1';和值可以是任何类型的对象。

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

删除一个值MyApp.vectorYouNeed [key] = null;并删除所有这些MyApp.vectorYouNeed = {};

#1


1  

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.

注意,key是一个字符串对象,即var key ='key1';和值可以是任何类型的对象。

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

删除一个值MyApp.vectorYouNeed [key] = null;并删除所有这些MyApp.vectorYouNeed = {};