ExtJS 在数据存储中搜索值
如何在数据存储中搜索特定记录?我尝试过 find() 和 findBy(),但都返回 -1。
var index = clientStore.find('ClientID', '37');
我有一个带有客户列表的组合框。我想要的是能够为该组合设置默认值。我使用 setValue 正确设置了值,甚至可以使用 setRawValue 设置显示值,但我似乎无法根据 clientID 查询数据存储并获取要在 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'}
])
});
How do I search a datastore for a specific record? I've tried find() and findBy(), but both return -1.
var index = clientStore.find('ClientID', '37');
I have a combo box with a list of clients. What I want is to be able to set a default value on that combo. I have the value setting correctly using setValue and I can even set the display value using setRawValue, but I can't seem to query the datastore based on the clientID and get the company name to use in setRawValue.
Does that make sense?
Here's the datastore code in response to the questions below (sorry it wouldn't let me paste it there)
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'}
])
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的配置存在几个问题。首先,读取的
id
属性应该是idProperty
属性。商店的id
属性应为storeId
属性(id
已弃用)。然后,当您在代码中引用clientStore
时,您的变量被称为frmClientStore
(可能是拼写错误)。最后:当您尝试从中检索记录时,您确定您的商店已加载吗?
尝试
There are several problems with your configuration. First of all the
id
-property of the read should be theidProperty
-property. The theid
-property of the store should be thestoreId
-property (id
is deprecated). And then your variable is calledfrmClientStore
while you're referencingclientStore
in your code (might be a typo).And finally: are you sure, your store has been loaded when you try to retrieve records from it?
Try
您列出的方式应该是正确的。但是,我应该指出,字段名称区分大小写。它也有可能正在搜索一个字符串(如您所列出的)而不是一个数字(这可能是您想要的)。
假设“
ClientID
”是正确的字段名称,您应该尝试以下操作:编辑
另外,我刚刚注意到您的 JsonReader 看起来有些不对劲。难道不应该更像这样吗:
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:EDIT
Also, I've just noticed that something looks off about your JsonReader. Shouldn't it be more like this: