Reputation: 1
im new to Sencha Touch 2, im trying to store values from json using store and models by proxy, but don't no where im wrong
My model
Ext.regModel('Product', {
fields: [
{name: 'name', type: 'string'},
{name: 'description', type: 'string'},
{name: 'price', type: 'float'},
{name: 'image_url', type: 'string'},
{name: 'in_stock', type: 'boolean'}
]
});
My store
Dzineapp.BlogStore = new Ext.data.Store({
model: 'Product',
autoLoad: false,
proxy: new Ext.data.AjaxProxy({
type: 'ajax',
url: 'http://localhost/products.json',
reader: {
type: 'json',
root: 'products'
},
writer: {
encode: true,
type: 'json'
}
})
});
Products.json
{
"products": [
{"name": "Some Product", "price": 9.99, "image_url": "product1.jpg", "in_stock": true},
{"name": "Another Product", "price": 7.50, "image_url": "product2.jpg", "in_stock": true},
{"name": "A third product", "price": 2.35, "image_url": "product3.jpg", "in_stock": false}
]
}
My Views
Dzineapp.blogPanel = new Ext.List({
id: 'bloglist',
store: Dzineapp.BlogStore,
itemTpl: '<div class="contact">{name}</div>'
});
But my App dosent show any values, any one can help me where im doing the mistake.. im just starter in sencha
Upvotes: 0
Views: 3421
Reputation: 1910
In your store configuration instead of using
root: 'products'
Try using
rootProperty: 'products'
Upvotes: 0
Reputation: 3889
1) You should use Ext.create() instead of new ... (but this should work anymway)
2) You should add ' around the store value in your list config
3) Check that you add your store to the stores[] in your app.js or add a require in your list.
4) With firebug/chrome dev tools check that your request is working ok (HTTP : 200) and that you get your json.
Hope this could help
Upvotes: 1
Reputation: 87
Can you update your store as below
Dzineapp.BlogStore = new Ext.data.Store({
model: 'Product',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'http://localhost/products.json',
reader: {
type: 'json',
root: 'products'
}
}
});
I hope so it works.
We have to load the store to display the data.
Thanks, Swathi.
Upvotes: 0