PDA

View Full Version : autocomplete problem



benmaya
4 Sep 2011, 2:33 AM
Hi,

I try to do something like this in my app:
http://www.java2s.com/Code/JavaScript/Ext-JS/AutocompletebasedonremoteJsonarray.htm

my code is


var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'modules/cost/find_member.php'

}),
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'total',

}, [
{name: 'member_id', mapping: 'member_id'},
{name: 'member_name', mapping: 'member_name'},

])
});

and as part of
MyDesktop.CostWindow.addCostWindow = new Ext.Window({
id:'addCostWindow',


{
xtype: 'combo',
store : ds,
fieldLabel : 'Query string',
displayField : 'title',
typeAhead : true,
loadingText : 'Searching...',
pageSize : 5,
id:'member_name',
renderTo : Ext.Element.get('member_name'),
width : 200
},


it almost works but... the result I get from the find_member.php is this when I type assa:

{"total":"3","results":{"member_id":["1","3","10"],"member_name":["Assaf Scialom","assaf","Assaf"]}}but it doesn't display as drop down menu. Any idea why?

skirtle
4 Sep 2011, 10:08 AM
The way you have your reader configured your response would need to be:


{"total":"3","results":[
{"member_id":"1","member_name":"Assaf Scialom"},
{"member_id":"3","member_name":"assaf"},
{"member_id":"10","member_name":"Assaf"}
]}

Getting it to work without changing the response would require a custom reader.