将项目列表链接到Carousel项目

时间:2012-10-17 08:16:25

标签: sencha-touch-2

我想将列表链接到另一个视图(轮播布局),例如carousel item no。 2。 我应该把这个括号放在哪里?

                onItemDisclosure: function() {
                    [......]
                }

我想实现类似carousel.setActiveItem(x)的东西 其中x是我的轮播内容。

2 个答案:

答案 0 :(得分:0)

我已经解决了你的问题。可能这对你有帮助。

<强> app.js

        Ext.application({
            name: "FrontApp",

            models: ["mymodel"],
            stores: ["mystore"],
            controllers: ["FrontAppController"],
            views: ["front","carousel"],

            launch: function () {
                var frontView = {
                    xtype: "frontview"
                };
                var Carousel = {
                    xtype: "carousel"
                };

                Ext.Viewport.add([frontView,Carousel]);//views called by x-type

            }
        });

<强> front.js

    Ext.define("FrontApp.view.front", {
    extend: "Ext.Panel",
    alias: "widget.frontview",

        config: {
            layout: {
                type: 'fit'
            },
            fullscreen: true,
            scrollable: true,
            items: [

            {
                    xtype: 'list',
                    itemId: 'myList',
                    scrollable: false,
                    itemTpl: '{firstName}',
                    store: 'mystore51',
                    onItemDisclosure: true,

            }
            ],
            listeners:
            [

                {
                  delegate: "#myList",
                  event: "disclose",
                  fn: "onListDisclose"
                }

            ]
            },


            onListDisclose: function (list, record, target, index, evt, options) {
                console.log("calling carousel..");
                this.fireEvent("carouselCommand", this,record, target, index, evt, options);

            }

    });

<强> carousel.js

 Ext.define('FrontApp.view.carousel', {
extend: 'Ext.carousel.Carousel',
xtype: 'carousel',

config: {

    items: [
        {
            xtype: 'panel',
            html: 'hello1'
        },
        {
            xtype: 'panel',
            html: 'hello2'
        },
        {
            xtype: 'panel',
            html: 'hello3'
        }
    ]
}

 });

<强> FrontAppController.js

        Ext.define("FrontApp.controller.FrontAppController", {
        extend: "Ext.app.Controller",
            config: {
                refs: {   
                    frontView: "frontview", 
                    carouselView:"carousel"         
                 },
                control: {
                frontView: { 
                        carouselCommand: "onCarouselCommand"
                     }
                 }
            },
            // Transitions
            slideLeftTransition: { type: 'slide', direction: 'left' },
            slideRightTransition: { type: 'slide', direction: 'right' },


             onCarouselCommand: function (list, record, target, index, e, eOpts) {  
                console.log("onCarouselCommand");
                 var a=this.getCarouselView().setActiveItem(index); // setting the carousel item according to list index.
                 Ext.Viewport.animateActiveItem(a, this.slideLeftTransition);
            },
             // Base Class functions.
            launch: function () {
                this.callParent(arguments);
                console.log("launch");

            },
            init: function () {
                this.callParent(arguments);
                console.log("init");
            }
        });

答案 1 :(得分:0)

onItemDisclosure: function(list, record, index) { 

//switch the view to carousel (my main content view) 
Ext.ComponentManager.get('comp').setActiveItem(1); 

//set active item for carousel according to chosen list 
Ext.ComponentManager.get('content').setActiveItem(index); 


}