I want to fetch data from JSON based on the employeeID. This is how the JSON data looks:
{"empDetails":
[
{
"employeeId": 1,
"employeeName": 'Anton DSouz',
"age": 25,
"birthday": '05/05/1988',
"sex": 'Male'
},
{
"employeeId": 2,
"employeeName": 'John Hussain',
"age": 26,
"birthday": '03/25/1987',
"sex": 'Female'
}
]
}
This is the code which I am using to fetch the data based on employeeID:
Ext.define('EmpDetails',{
extend: 'Ext.data.Model',
fields: [
{name: 'employeeId', type: 'int'},
{name: 'employeeName', type: 'string'},
{name: 'age', type: 'int'},
{name: 'birthday', type: 'date', dateFormat: 'd/m/Y'},
{name: 'sex', type: 'string', defaultValue: 'Male'}
],
proxy: {
type: 'rest',
url: 'data.json',
format: 'json',
reader: {
type: 'json',
root: 'empDetails'
}
}
});
Ext.onReady(function(){
EmpDetails.load(1,{
success: function(empDetails){
console.log("Age: " + empDetails.get('age'));
}
});
});
But it is not working. The URL it is looking for is incorrect:
../../Proxy/data.json/1.json
1.json does not exists at all, i is the employeeID present in data.json.
Please help
Because you’re using a rest proxy, it’s attempting to append the id to the url so it looks like a normal rest request. You should use an ajax proxy instead.