【问题标题】:Extjs combobox to display store records based on a propertyExtjs 组合框根据属性显示商店记录
【发布时间】:2017-11-17 23:07:20
【问题描述】:

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

通过在组合框中调用商店“媒体”:

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

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

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

其中 type == 1 用于图像。

谢谢。

【问题讨论】:

  • 请分享一个小提琴和你的 ExtJs 版本。您需要通过使用组合框或直接在商店中将过滤器传递给商店 - 您可能需要查看商店的 filterBy 函数。

标签: extjs combobox model store


【解决方案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'}
    ]
}

`

【讨论】:

    【解决方案2】:

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

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

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

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

    【讨论】:

    • 据我所知,默认情况下它既不 === 也不 ==,只有 .toString().startsWith()。您必须将exactMatch:true 配置添加到过滤器才能获得==,并且您无法使用该属性实现===,只能通过一个函数。您可以亲自查看整个混乱情况here
    猜你喜欢
    • 2011-12-24
    • 2018-03-29
    • 2011-01-02
    • 1970-01-01
    • 2014-09-06
    • 2013-02-03
    • 1970-01-01
    • 2014-12-09
    • 2013-08-16
    相关资源
    最近更新 更多