我尝试使用动态创建的存储(来自数组)填充 ext js 7.3.1 中的组合框。
这是我的组合框代码:
{
xtype: 'combobox',
name: 'cb_demo',
itemId: 'cb-demo',
label: 'Demo',
store: cb_store_demo,
displayField: 'text',
valueField: 'value',
queryMode: 'local',
editable: false,
//displayTpl: '{text.text}',
itemTpl: '<div data-qalign="b-t" data-qanchor="true" data-qtip="{text}">{text} </div>',
autocomplete: false,
}
我通过创建 SimpleStore 来填充 store:
var combo = Ext.getCmp('main').down('#cb-demo');
cb_store_demo = new Ext.data.SimpleStore
({
fields : ['text','value'],
data : demo_arr,
});
combo.setStore(cb_store_demo );
combo.getStore().load();
combo.setValue('');
我尝试使用这个 php 函数从数据库中获取数据:
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
if($row['id'] != '')
{
$singleItem = array();
$singleItem['text'] = $row['name'];
$singleItem['value'] = $row['id'];
$results['demo'][] = [$singleItem];
}
}
并使用 ajax/json 在 ext js 中获取它 - 我在其上使用 Ext.decode。
无论我如何尝试访问组合框上的数据,它都不起作用。我可以让下拉菜单正常工作,但是当我选择值字段为空/激活多选时,我收到一个错误,该值必须是唯一的。
有人可以帮我吗?