ExtJS使用远程JSON存储分页组合。使用分页显示所选值 [英] ExtJS paged combo with remote JSON store. Display selected value with paging
问题描述
我有一个带有远程存储的ExtJS组合,它返回JSON格式的数据。当我在第一页上选择一个值(例如),然后导航到另一个页面时,组合显示选择id,而不是值。
I've got an ExtJS combo with remote store, which returns to me data in JSON format. When I select a value on the first page (for example) and then navigate to another page, the combo display selected id, not the value.
如何始终显示所选值?
代码:
Ext.onReady(function() {
Ext.define('Model', {
extend: 'Ext.data.Model',
fields: ['title'],
idProperty: 'threadid'
});
var store = Ext.create('Ext.data.Store', {
pageSize: 50,
model: 'Model',
remoteSort: true,
proxy: {
type: 'jsonp',
url: 'http://www.sencha.com/forum/topics-browse-remote.php',
reader: {
root: 'topics',
totalProperty: 'totalCount'
},
simpleSortMode: true
}
});
var combo = Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Value',
store: store,
queryMode: 'remote',
displayField: 'title',
valueField: 'threadid',
pageSize: 50,
labelWidth: 50,
width: 300,
padding: '60 0 0 0'
});
Ext.create('Ext.window.Window', {
title: 'Hello',
height: 200,
width: 400,
layout: { type: 'vbox', align: 'center' },
items: combo
}).show();
})
示例: http://jsfiddle.net/coshmos/5wT6H/
更多信息(案例研究):
我有一个表,我可以更新记录。我点击一个项目,然后我的服务器从数据库返回值。然后出现一个带有UI的窗口。对于所有分页的组合,它只返回id的。所以,直到我不导航到带有返回ID的项目的页面,我没有看到一个值。如果我禁用分页和加载所有的值,所有的工作按预期,但加载数千个值是不好的。
More information (case study):
I've got a table where I can update records. I click on an item and then my server return values from a database. Then a window with UI appear. For all paged combo it's return only id's. So until I don't navigate to page with item with returned id, I don't see a value. If I disable paging and load all values, all works as expected, but loading of thousands values is not good.
推荐答案
可以这样修改:
Ext.override(Ext.form.field.ComboBox,{
findRecord: function(field, value) {
var foundRec = null;
Ext.each(this.lastSelection, function(rec) {
if (rec.get(field) === value) {
foundRec = rec;
return false; // stop 'each' loop
}
});
if (foundRec) {
return foundRec;
} else {
return this.callParent(arguments);
}
}
});
试试看: http://jsfiddle.net/5wT6H/3/
这篇关于ExtJS使用远程JSON存储分页组合。使用分页显示所选值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!