问题
Here my code for list using Sencha touch2 , I have a rest service and I need to be able to load my store for my list view.Follows
var tab= Ext.create('Ext.List', {
width: 320,
height: 290,
store: {
fields: ['ext_xtype','imgURL','arimg'],
data: [{
ext_xtype: 'Harry Potter 4',
imgURL:'bo.png',
arimg:'arrow.png'
},{
ext_xtype: 'Iphone5 64gb',
imgURL:'mo.png',
arimg:'arrow.png'
},{
ext_xtype: 'Hill Figure',
imgURL:'wa.png',
arimg:'arrow.png'
}]
},
itemTpl: '<img src="{imgURL}" width="35" heigh="35"></img><span>   {ext_xtype}<img src="{arimg}" width="25" height="25" align="right"></img>'
});
i have tried the following link Sencha with proxy quest but couldnt help to proceed.Here the rest JSON method.
Method: GET
URL: http://117.218.59.157:8080/WishList/ShowItems/userID=?
How shall i import the json to load in LIST
#EDIT
var tab= Ext.create('Ext.List', {
width: 320,
height: 290,
//ui: 'round',
store: {
proxy: {
type: 'ajax',
url: 'http://117.218.59.157:8080/WishList/ShowItems/userID=1',
reader: {
type: 'json'
}
}
fields: [
{ imgURL: 'itemID' },
{ ext_xtype: 'itemName'},
{ arimg: 'itemImage'},
],
},
itemTpl: '<img src="{imgURL}" width="35" heigh="35"></img><span>   {ext_xtype}<img src="{arimg}" width="25" height="25" align="right"></img>'
});
回答1:
you had forgotten to set root
and idProperty
of JSON reader! It should be like below:
proxy: {
type: 'ajax',
url: 'http://117.218.59.157:8080/WishList/ShowItems/userID=1',
method: 'GET'
},
reader: {
type: 'json',
root: 'items',
idProperty: 'itemID'
}
Besides, your JSON data should be as follows:
{"items":
[{
"itemID": "1",
"errorMsg": "",
"itemName": "Airplane",
"itemDesc": "Model NEW 2003"
},
{
"itemID": "2",
"errorMsg": "",
"itemName": "Bike",
"itemDesc": "Model NEW 2003"
}
]
}
来源:https://stackoverflow.com/questions/18531258/load-store-for-list-using-json