如何搜索特定记录的数据存储?我尝试过()和findby(),但返回-1。

var index = clientStore.find('ClientID', '37');
.

我有一个包含客户列表的组合框。我想要的是能够在该组合上设置默认值。我使用setValue正确设置值,我甚至可以使用setrawvalue设置显示值,但我似乎无法根据客户机查询数据存储,并获取在SetraWvalue中使用的公司名称。

这是有意义的吗?

这是数据存储码,以响应下面的问题(对不起它不会让我粘贴它)

var frmClientStore = new Ext.data.Store({
    id: 'frmClientStore',
    proxy: new Ext.data.HttpProxy({
        url: 'url here', 
        method: 'POST'
    }),
    reader: new Ext.data.JsonReader({
        root: 'rows',
        id: 'recordID'
    },[
        {name: 'recordID', type: 'int', mapping: 'recordID'},
        {name: 'ClientID', type: 'int', mapping: 'clientID'},
        {name: 'CompanyName', type: 'string', mapping: 'companyName'}
      ])
});
.

有帮助吗?

解决方案

There are several problems with your configuration. First of all the id-property of the read should be the idProperty-property. The the id-property of the store should be the storeId-property (id is deprecated). And then your variable is called frmClientStore while you're referencing clientStore in your code (might be a typo).

var frmClientStore = new Ext.data.Store({
    storeId: 'frmClientStore',
    proxy: new Ext.data.HttpProxy({
        url: 'url here', 
        method: 'POST'
    }),
    reader: new Ext.data.JsonReader({
        root: 'rows',
        idProperty: 'recordID'
    },[
        {name: 'recordID', type: 'int', mapping: 'recordID'},
        {name: 'ClientID', type: 'int', mapping: 'clientID'},
        {name: 'CompanyName', type: 'string', mapping: 'companyName'}
      ])
});

And finally: are you sure, your store has been loaded when you try to retrieve records from it?

Try

frmClientStore.load({
    callback: function(rs) {
        console.log(rs);
        console.log(this.find('ClientID', '37'));
    }
});

其他提示

The way that you've listed should be correct. However, I should point out that the field name is case sensitive. It is also possible that it is searching for a string (as you've listed) instead of a number (which may be what you want).

Supposing that 'ClientID' is the correct field name, you should try the following:

var index = clientStore.find('ClientID', 37);

EDIT

Also, I've just noticed that something looks off about your JsonReader. Shouldn't it be more like this:

//...
reader: new Ext.data.JsonReader({
    root: 'rows',
    id: 'recordID'
    fields: [ //list fields here as part of the JsonReader
        {name: 'recordID', type: 'int', mapping: 'recordID'},
        {name: 'ClientID', type: 'int', mapping: 'clientID'},
        {name: 'CompanyName', type: 'string', mapping: 'companyName'}
    ]
})
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top