【问题标题】:Sencha filter data from storeSencha 过滤来自商店的数据
【发布时间】:2014-01-10 18:27:30
【问题描述】:

我是煎茶触摸的新用户

我有这家店

Ext.define('Final.store.Fotos',{
extend: 'Ext.data.Store',
requires: ['Final.model.Foto'],
config:{
    model: 'Final.model.Foto',
    storeId: 'Fotos',
    autoLoad: true,
    proxy: {
        type:'ajax',
        url: '../../../prueba/index.cfm',
        reader:'json'
    }
}
});

一个模型

 Ext.define('Final.model.Foto',{
extend: 'Ext.data.Model',
config:{
    fields:[
        {name: 'caja', type: 'string'},
        {name: 'foto_id', type: 'int'},
        {name: 'id_caja', type: 'int'},
        {name: 'foto', type: 'string'}
    ]
}
});

还有一个控制器

Ext.define('Final.controller.controladorCaja',{
extend: 'Ext.app.Controller',
config: {
    stores: ['Cajas', 'Fotos'],
    models: ['Caja', 'Foto'],

    refs: {
        cajaLista: 'list'
    },

    control: {
        cajaLista: {
            itemtap: 'clickCaja'
        }
    }
},

clickCaja: function(series, item, evento, caja){
    var idcaja = caja.data.caja;
    var vista = Ext.getCmp('principal');
    vista.push({
        title: ' Fotos',
        items : [{
            extend: 'Ext.navigation.View',
            config: {
                id: 'fotos'
            },
            items: [{
                xtype: 'button',
                text: 'fsf'
            }]
        }]
    });
}
});

在我的数据库中,我有 2 个表,其中一个带有 cajas 或 boxes,另一个带有与 id_caja 或 id_box 相关的图像

因此,在煎茶的其他视图中,我在xtype: list 中显示了框的名称。所以,我的问题是当我点击列表中的一个项目并触发函数clickCaja 时,获取点击的元素的 id 并通过 id 框过滤图像

【问题讨论】:

    标签: javascript extjs sencha-touch


    【解决方案1】:

    如果您的照片列表默认显示所有照片并且应该限制为特定的“caja”(如果单击),则可以使用built in store filter。

    var idcaja = caja.data.caja;
    Ext.getStore('Fotos').filterBy(function(record, id){
       return record.data.id_caja == idcaja;
    }, this);
    

    编辑: 如果您使用默认的Ext.tab.Panel,您可以使用 setActiveItem 方法在选项卡之间切换。

    示例:

    在您的主视图中

    Ext.define('App.view.Main', {
        extend: 'Ext.tab.Panel',
        xtype: 'main',
        id : 'mainpanel', //set an id for your tab panel
        ...
    }
    

    在您的控制器中:

    refs: {
      ...,
      mainPanel :'#mainpanel' //get a reference to the main panel
    },
    

    在您的事件处理程序中,您可以使用类似...

    this.getMainPanel().setActiveItem('fotoList'); //fotoList = xtype of your foto view
    

    ...切换到您的照片列表。

    【讨论】:

    • 谢谢,非常有趣,但是例如,如果我有 fotos 视图和 principal("main") 视图,我怎么能在视图之间切换,原则上我有控制器,然后它加载存储(cajas)和模型(caja)然后使用 itemtap 我想获取项目的 id 并转到另一个视图“fotos”并过滤(只显示该 id caja 的照片)
    • 我添加了一个在两个选项卡之间切换的解决方案。假设您正在使用带有两个选项卡的选项卡面板,其中第一个选项卡显示 cajas,第二个选项卡显示照片。如果您只想在标签面板中显示“cajas”,您可以创建(Ext.create)foto-list-panel 并将其添加到视口。
    猜你喜欢
    • 2015-12-28
    • 1970-01-01
    • 2013-04-16
    • 1970-01-01
    • 2012-05-29
    • 1970-01-01
    • 2011-12-02
    • 1970-01-01
    • 2015-07-30
    相关资源
    最近更新 更多