我有一个带有远程存储的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: 'www.sencha/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(); })示例: jsfiddle/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); } } });试试看: jsfiddle/5wT6H/3/
更多推荐
ExtJS使用远程JSON存储分页组合。使用分页显示所选值
发布评论