开发者

insert in sencha touch data store

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 开发者_StackOverflow中文版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'.

Model:

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

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?

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.

Store:

    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.

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?


Just an update of the YDL answer. As per the dataView should be related to the updated store, the last sentence dataView.update() should not be needed, due to the automatic update of the views related to a store when it change.

new Ext.DataView({
    store: MyStore,
    itemSelector: 'div.thumb',
    tpl: thumbTpl
});

later, if I do the following, the new item should be displayed in views (List, DataView, etc.) that have MyStore as store.

MyStore.add(newItem);

HTH. Milton Rodríguez.


If you are trying to pass in an object that was returned from a getValue() on your form, make sure that you run a

myStore.sync(); 

after you have called the add() method, or you wont see it in your browsers local store.


It is Very easy try these

// first get those values and store in locally

     var A_select1=Ext.getCmp('select1').getValue();  // get value

      localStorage.setItem("Adult1_select1",A_select1); // set localStore


      var AdultSalutation={

                     'Adult1_select1':A_select1,    // assign the value                                                   

            };                                       

    var AdultSalutationstore = Ext.getStore('Adult_AdultSalutationstore'); // get store

        AdultSalutationstore.add(AdultSalutation);  // add object   

        AdultSalutationstore.sync();    // sync 

        AdultSalutationstore.load();    // load                                                 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜