Extjs 基于条件从json获取记录

Extjs 基于条件从json获取记录,extjs,extjs4,extjs4.1,Extjs,Extjs4,Extjs4.1,我想根据employeeID从JSON获取数据。以下是JSON数据的外观: {"empDetails": [ { "employeeId": 1, "employeeName": 'Anton DSouz', "age": 25, "birthday": '05/05/1988', "sex": 'Male' }, { "employeeId": 2, "emp

我想根据employeeID从JSON获取数据。以下是JSON数据的外观:

{"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'            
    }
]
}

这是我用来根据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'));
    }
});
});
但它不起作用。它正在查找的URL不正确:

../../Proxy/data.json/1.json
1.json根本不存在,i是data.json中的employeeID


请提供帮助

因为您使用的是rest代理,它试图将id附加到url,因此看起来像是正常的rest请求。您应该改用ajax代理

type: 'ajax'

如果我将
rest
更改为
ajax
,它会起作用,但没有得到预期的结果。如果我的数据是1,那么年龄是25岁。但是如果我再次发送2,那么返回的年龄也是25岁。根据我上面发布的json数据,应该是26。请让我知道上面代码中的问题在哪里。您总是返回所有记录。如果要传递参数,则需要在服务器代码中应用适当的筛选器以获取正确的记录。@user182944,如果这有效,请将其标记为已解决,这将有助于您处境中的其他人