Sencha触摸存储同步

发布于 2024-12-05 07:11:47 字数 327 浏览 3 评论 0原文

我是Sencha Touch的新手,仍然对其数据处理模式不太自信。我想设置应用程序的方式是这样的:

  1. 通过Ajax从远程服务器中检索用户的数据。

  2. 将其保存在本地存储中。任何修改(编辑,添加,删除项目)更新本地数据。

  3. 在某个时间点(用户单击“同步”,用户注销或类似的内容时,本地存储的存储数据再次与服务器同步,再次通过请求Ajax。 >

那么,我的应用程序的基本结构是什么,以实现这种模式?而且,当我们在这里时,是否有一种方法可以在Sencha Touch中使用本地数据库(与本地键值存储相对)?

I’m new to Sencha Touch and still not quite confident with its data handling patterns. The way I want to set up my application is something like this:

  1. Retrieve the user’s data from the remote server via AJAX.

  2. Save it in the local storage. Any modifications (editing, adding, deleting items) update the local data.

  3. At some point in time (when the user clicks ‘sync’, when the user logs out, or something like that), the locally stored stored data is synced with the server, again, through an request AJAX.

So what would the basic structure of my application be, to achieve this pattern? And also, while we are here, is there a way to use a local database (as opposed to local key-value storage) for a specified store in Sencha Touch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗藏城府 2024-12-12 07:11:47

首先,Sencha.IO Sync 提供了您正在寻找的功能。它仍处于测试阶段,但它可能会完全满足您的需要,并且您不必自己托管数据库:
http://www.sencha.com/products/io

对我来说,我构建的应用程序使用 localstorage 代理在本地存储数据。这非常简单。以下是使用数据存储的几个示例:

  1. http://www .sencha.com/learn/take-sencha-touch-apps-offline/
  2. http://data-that.blogspot.com /2011/01/local-storage-proxy-with-sencha-touch.html
  3. http://davehiren.blogspot.com/2011/09/sencha -touch-working-with-models.html
  4. http://www.sencha.com/learn/working-with-forms/

稍后在应用程序中,我有一个 AJAX 调用,它将获取所有本地数据并将其发送到服务器生成一些报告。

一旦正确设置了商店和模型,就可以轻松地从中获取数据。例如,我有一个 contactInfo 存储,它只有一个条目:

var myContactInfo = contactInfo.first().data;

我有另一个名为设置的存储,它有许多条目。我可以像这样轻松地检索它们(尽管可能有更好的方法):

var settingsArr = []
settings.each(function() {
    settingsArr.push(this.data);
});

然后我可以轻松地将其发送到服务器,如下所示:

var data = {settings: settingsArr, contactInfo: myContactInfo};
Ext.Ajax.request({
url: 'save.php',
params: {json: Ext.encode(data)},
success: function(response, opts) {
       // celebrate
}
});

与所有事情一样,仔细查看示例,一旦您拥有了 API 应该会为您提供帮助基本弄清楚了:
http://dev.sencha.com/deploy/touch/ docs/?class=Ext.data.Store

First of all Sencha.IO Sync provides the functionality that you're looking for. It's still in beta, but it probably will do exactly what you need and you won't have to host the database yourself:
http://www.sencha.com/products/io

For me I've built apps that use the localstorage proxy to store data locally. It's super easy. Here are a couple of examples of using data storage:

  1. http://www.sencha.com/learn/taking-sencha-touch-apps-offline/
  2. http://data-that.blogspot.com/2011/01/local-storage-proxy-with-sencha-touch.html
  3. http://davehiren.blogspot.com/2011/09/sencha-touch-working-with-models.html
  4. http://www.sencha.com/learn/working-with-forms/

Later in the app I have an AJAX call that will take all of that local data and send it up to the server to generate some reports.

Once you have your stores and models setup correctly it's easy to get the data back out of them. For example I have a contactInfo store that only ever has one entry:

var myContactInfo = contactInfo.first().data;

I have another store called settings, which has many entries. I can easily retrieve them like this (though there may be a better way):

var settingsArr = []
settings.each(function() {
    settingsArr.push(this.data);
});

I then can easily send this up to the server like so:

var data = {settings: settingsArr, contactInfo: myContactInfo};
Ext.Ajax.request({
url: 'save.php',
params: {json: Ext.encode(data)},
success: function(response, opts) {
       // celebrate
}
});

As with all things a good look at the examples and the API should help you once you have the basics figured out:
http://dev.sencha.com/deploy/touch/docs/?class=Ext.data.Store

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文