PDA

View Full Version : Data CRUD example?



hopthuden
23 Jan 2011, 8:09 AM
Is there an example for LOCAL database CRUD operation in Sencha Framework? I coudn't find any a simple code for this. Can someone help me?

28 Jan 2011, 11:04 AM
what do you mean by LOCAL database? as in LOCAL storage? or LOCAL to your dev environment?

hopthuden
30 Jan 2011, 9:50 PM
Sorry for late reply, I mean Local storage.

ninoguba
11 Feb 2011, 10:14 AM
This is easy. You just have to use the localStorageProxy. Here's some sample code I'm using:




app.models.Card = Ext.regModel("app.models.Card", {


fields: [

{name: "id", type: "int"},
{name: "name", type: "string"},
{name: "type", type: "string"}






],

proxy: {
type: 'localstorage',
id: 'yourCards'
}
});





app.stores.cards = new Ext.data.Store({

model: "app.models.Card"


});



Then if you want to preload it with sample data:





localStorage.clear();

app.stores.cards.add({
name: 'Card 1',
type: 'Card'
});
app.stores.cards.add({
name: 'Card 2',
type: 'Card'
});
app.stores.cards.add({
name: 'Card 3',
type: 'Card'
});


app.stores.cards.sync();


And this code can work with the MVC walkthrough Sencha provided for their Contacts App but instead of using your phones Address Book, your using Web Storage.

hopthuden
13 Feb 2011, 6:27 PM
Many thanks ninoguba,
I will try this code. But sorry for an idiotic question that if anyone can submit a simple Sencha code like this: http://www.stocksfoundation.com/project/sample-crud (it coded by Titanium framework). I think it will be helpful for beginners like me.

http://farm5.static.flickr.com/4115/4761529374_7593294a1d.jpg
http://farm5.static.flickr.com/4073/4760896743_b687242cab.jpg
http://farm5.static.flickr.com/4135/4761528766_94533a4f6b.jpg
http://farm5.static.flickr.com/4081/4760896049_a947bd5382.jpg

Thanks.