Sencha Touch 中使用的数据结构类似于 Blackberry 中的 Vector
我是 sencha Touch 的初学者,基本上我是一名黑莓开发人员。目前我们正在迁移我们的应用程序以支持 Sencha Touch 1.1。现在我有一些业务解决方案,例如我想将选定的值存储在本地数据库中。我的意思是我有多个屏幕,一旦用户在每个屏幕中选择一个值,数据就应以以下格式保存。
[{'key1': "value1", 'key2': "value2", 'key3': "value3" ,'key4': "value4", 'key5': "value5"}]
1.首先,值需要保存在键值对中
2.键应起到主键的作用,键不应重复。
3.应该在应用程序生命周期或应用程序会话期间可用,不需要永久保存数据。
我遇到过 LocalStorageProxy、JsonStore 等概念。我不明白我可以使用哪一个来满足我的具体要求。
可能我的问题有点令人困惑。我已经在 Blackberry Java 中使用向量实现了相同的效果,因此任何与此类似的数据结构都可以帮助我。 的基本操作
- 需要像创建
- 添加
- 删除
- 删除所有
- 基于键的获取元素之类
请建议我一些示例或一些代码快照,这可能会帮助我实现这一目标。
编辑:1
我已按照 @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 无法使用上述语法检索元素。
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
- Create
- Add
- Remove
- Remove all
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不需要永久保存数据,那么您可以只拥有一个具有所需属性的全局对象。首先像这样定义对象:
然后像这样将键值对添加到对象中
并像这样获取它们
注意 key 是一个字符串对象,即
var key='key1';
并且 value 可以是任何类型的对象。删除一个值
MyApp.vectorYouNeed[key] = null;
并删除所有值MyApp.vectorYouNeed = {};
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:
Then add the key-value pairs to the object like this
And fetch them like this
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 themMyApp.vectorYouNeed = {};