简体   繁体   English

离线状态下的Sencha touch应用

[英]Sencha touch app in offline

My app is almost completed with sencha touch2.3, now I want to make it working in offline mode. 我的应用几乎已使用sencha touch2.3完成,现在我想使其在离线模式下工作。

I need to load lot of data and images from my server application, It's working fine in online mode. 我需要从服务器应用程序中加载大量数据和图像,在联机模式下可以正常工作。

Problems I need to solve and what I have done 我需要解决的问题和已经完成的工作

1. Need to store data in websql (using sql proxy) when there is a network. 1.有网络时,需要将数据存储在websql中(使用sql代理)。

I did this by.. if there is a network,I am loading online store and adding all the record to offline store. 我这样做是..如果有网络,我正在加载在线商店并将所有记录添加到离线商店。

Ext.getStore('foodGroup').load({
    callback: function(records, operation, success) {
        var offFoodGrup = Ext.getStore('offFoodGroup');
        offFoodGrup.add(records);
        offFoodGrup.sync();
        offFoodGrup.load();
      }
    },
    scope: this
});

2. I need to update the offline data if needed, I tried but it's not working. 2.如果需要,我需要更新脱机数据,但是尝试了但无法正常工作。 It adds duplicate data. 它添加重复数据。

Ext.getStore('foodGroup').load({
    callback: function(records, operation, success) {
        var offFoodGrup = Ext.getStore('offFoodGroup');
        if(records.length != (localStorage.offFoodGroup || 0)){
            offFoodGrup.removeAll();
            offFoodGrup.sync();
            offFoodGrup.load({
                callback: function(offRecords, operation, success) {
                    offFoodGrup.add(records);
                    offFoodGrup.sync();
                    offFoodGrup.load();
                    localStorage.offFoodGroup = offFoodGrup.getAllCount();
                },
                scope: this
            });
        }
    },
    scope: this
});

3. I need to show lot of images offline, so I though converting image url to base64 string may solve my problem. 3.我需要脱机显示很多图像,因此尽管将图像url转换为base64字符串可能可以解决我的问题。 How can I do this in following code. 我如何在下面的代码中做到这一点。

Ext.define('MyAPP.view.PhotoContainer', {
    extend: 'Ext.Container',  
    xtype : 'photoContainer',
    config:{            
        tpl: Ext.create('Ext.XTemplate',
                        '<ul class="foodList">',
                            '<tpl for=".">',
                            '<li class="foodContainer" code="{code}">',
                            '<img class="food" src="'+localStorage.httpServerPrefix+'food/showImage/{code}" alt="{name}"/>',
                            '<p code="{code}" class="foodnamestyle">{[this.getpreferedlanguage(values)]}</p>',
                            '</li>',
                            '</tpl>',
                        '</ul>'
        }),
        store : 'FoodStore'
    }
});

It would be helpful to see your code for the FoodGroup model and online and offline stores if thats ok. 如果可以的话,查看FoodGroup模型以及在线和离线商店的代码将很有帮助。

With the image in base64 format just use a data url like this: 对于base64格式的图像,只需使用如下数据URL:

<img src="data:image/png;base64,{Your Base64 Image Data}"/>

Hope that helps, and if you can post your models and stores I might be able to help with that. 希望对您有所帮助,如果您可以发布模型和商店,我也许可以提供帮助。

Thanks, Tristan 谢谢特里斯坦

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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