基于 属性 显示商店记录的 Extjs 组合框

Extjs combobox to display store records based on a property

我是 Sencha 的新手,我的问题如下:

通过在组合框中调用商店 'Media':

xtype: 'combobox', itemId: 'mediaPicker', store: Ext.create('web.store.Media'), fieldLabel: 'Image', emptyText: 'Choose an Image'

我收到了预期的媒体列表,但是,根据商店模型中的以下 属性,我如何才能收到只有图像的列表:

{ name: 'type', type: 'int' },

其中图像类型 == 1。

谢谢。

尝试实现这段代码:

var my_images_store  =  new Ext.data.JsonStore({ 
                        url: 'myfilefunc.php'   
                        ,autoLoad: true
                        ,fields:[id,desc]
                        ,root: 'images'
                }); 

`

url: 将 url 放到您的业务逻辑中(php 函数例如) fields: 结果集返回的字段名称 root: 结果集的名称

结果集示例:`

{
    images: [
        {id: '1', desc:'x'},
        {id: '2', desc:'y'}
    ]
}

`

您需要为您的商店添加过滤器。

store: Ext.create('web.store.Media') 更改为

store: Ext.create('web.store.Media',{
    filters: [{
        property: 'type',
        value: 1
        }])

注意:我不确定以上是否会进行严格的 === 或松散的 == 比较。如果它不适合您,那么您可以使用函数在商店中指定过滤器。查看商店过滤文档。