插入sencha touch数据存储中 [英] insert in sencha touch data store

查看:54
本文介绍了插入sencha touch数据存储中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释插入操作如何在数据存储区中添加记录 与临场:标题",信息"和价格"? 因为我尝试了一些东西,但没有一个起作用.而sencha网站并没有说清楚.

Could someone please explain how the insert works to add a record in a datastore with tha fields: "title", "info" and "price"? because i tried some things and none of them work. and the sencha website doesnt make it very clear.

推荐答案

向现有商店添加新商品实际上并不难.

Adding a new item to an existing Store isn't that hard actually.

首先,您需要配置模型和存储.在您的问题中,将字段命名为标题",信息"和价格".

First of you will need to configure your model and store. In your question you name the fields 'title, 'info' and 'price'.

型号:

Ext.regModel('myModel', { 
    fields: [
        {name: 'id', type: 'int' },
        {name: 'title', type: 'string' },
        {name: 'info', type: 'string' },
        {name: 'price', type: 'int' }           
    ]
});

接下来,根据上述模型,配置将保存数据的存储.我认为,就您而言,它应该是一个没有通过JSON预加载任何数据的模型?

Next you configure the store that will hold the data, based on the above model. I think that, in your case, it should be a model without any data preloaded via, for example, JSON?

因此,让我们进行本地存储(空存储).商店由模型(myModel)组成,您给它提供一个storeID(以便以后可以通过该ID引用商店).代理是本地存储,商店的唯一ID将是模型的ID字段.

So lets make a localstorage (empty store). The Store consists of the model (myModel), you give it a storeID (so that you can later on reference the store by this ID). The proxy is localstorage and the unique ID of the Store will be the ID field of the Model.

商店:

    var myStore = new Ext.data.Store({ 

        model: "myModel",
        storeId: "myStoreID",
        proxy: {
            type: "localstorage",
            id: "id"            
        }
    });

现在,假设您具有某种形式(用户可以在其中添加输入的标题,信息和价格,并且您想在提交时将这些项目添加到现有商店中.

Now, suppose you have some kind of Form (in which the user can add input a title, info and price, and you want to add these items to the existing store on submittal.

现在必须在提交"按钮的处理程序内调用"商店,并在其上执行添加功能.在此add函数中,您将必须定义参数(模型参数)和要插入的数据.

Within the handler of the submittal button you now have to 'call' the store, and perform the add function on it. Within this add function you will have to define the params (the model params) and the data to insert.

下面,我将固定数据和变量混合使用.

Below I have used a mixture of fixed data and a variable to insert.

myStoreID.add({ title: "Mijn Titel", info: "Informatie, price: prijsvar });

现在将填充商店,现在将填充可用的额外数据记录.例如,假设商店已附加到数据视图,则可以执行以下操作:

The store will now be filled will now be filled with an extra data-record which you can use. Lets say for example that the store is attached to a dataview, then you can perform:

dataView.update();

以上内容不是完整的教程,但是我认为这对您有帮助吗?

The above isn't a full tutorial, but I think this will help you along?

这篇关于插入sencha touch数据存储中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆