JSON 商店中的 Sencha Touch 轮播

发布于 2024-12-03 12:28:39 字数 4314 浏览 0 评论 0原文

我正在使用 Sencha Touch 构建一个 Wordpress 网站。我创建了一个插件,可以将帖子转换为 JSON 以便应用程序读取。

在应用程序“帖子视图”中,我正在加载帖子信息(标题、正文等),并且我希望有一个轮播来显示我在帖子中放入的 json 数组“图像”中的所有图像。

我的应用程序使用 MVC 结构(因为我喜欢拔牙的感觉),因此我需要一个帖子列表来将数据传递到 Single Posts 面板,然后将 Images 数组放入轮播中。

目标是从列表中选择一个帖子,将数据加载到 postsingleview(当前正在工作)中,然后将该帖子中的图像加载到轮播中。

非常感谢任何和所有建议。

这是我到目前为止所拥有的:

JSON: http://pastie.org/2497239 (Stack 的代码包装器不会让我显示json,这是pastebin)

PostListView:

App.views.PostListView = Ext.extend(Ext.Panel, {

    postStore: Ext.emptyFn,
    postList: Ext.emptyFn,
    id:'postlistview',
    layout: 'card',

    initComponent: function () {

        this.postList = new Ext.List({
            store: App.stores.postStore,
            grouped: true,
            emptyText: '<div style="margin:5px;">No notes cached.</div>',
            onItemDisclosure: true,
            indexBar: true,
            itemTpl: '<div class="list-item-title">{title}</div>',

        });

        this.postList.on('disclose', function (record) {
            this.onViewPost(record);
        }, this),

        this.items = [this.postList];

        App.views.PostListView.superclass.initComponent.call(this);
    },

    onViewPost: function (record) {

        Ext.dispatch({
            controller: App.controllers.masterController,
            action: 'viewpost',
            record: record,
        });
    },

});

具有“ViewPost”操作的主控制器:

    'viewpost': function (options) {

        App.views.postSingleView.bodycard.update(options.record.data);
        App.views.postSingleView.funfactcard.update(options.record.data);
        App.views.postSingleView.crosscard.update(options.record.data);
        App.views.postSingleView.historycard.update(options.record.data);
        App.views.postSingleView.architectcard.update(options.record.data);
        App.views.postSingleView.commentcard.update(options.record.data);
        App.views.postSingleView.dealscard.update(options.record.data);

        App.views.postView.setActiveItem(
            App.views.postSingleView,
            { type: 'slide', direction: 'left' }
        );
    },

发布单个视图(显示帖子中的数据)

App.views.PostSingleView = Ext.extend(Ext.Panel, { 

    title:'Single Post',
    id:'postsingleview',
    layout:{
        type:'vbox',
        align:'stretch',
        pack:'end'
    },
    defaults: { flex: 1 },

    initComponent: function () {

        this.bodycard = new Ext.Component({
            title:'Info',
            scroll:'vertical',
            cls : 'card bottomcard card3',
            iconCls:'info',
            tpl: '<tpl for=".">' + 
                    '<div id="bottomcard-container">{body}</div>' +
                 '</tpl>',
        });

        [... There are 7 Ext.Components, but I want to keep it short so I'm deleting them for Display on Stack ]


        this.postSinglePanel = new Ext.TabPanel({
            dock:'bottom',
            id:'singlepost-bottompanel',
            items:[ 
                this.bodycard, 
                this.funfactcard, 
                this.crosscard, 
                this.historycard, 
                this.architectcard, 
                this.commentcard, 
                this.dealscard, 

            ],
            tabBar:{
                dock:'bottom',
                scroll:'horizontal',
                layout:{
                    pack:'center',
                },
            },
        });


        var numberOfPages = 4;
        // Create pages for the carousel
        var pages = [];
        for (var i=0; i<numberOfPages; i++) {
            pages.push(new Ext.Component({
                id: 'page'+i,
                cls: 'page',
                tpl: '<tpl for=".">{body}</tpl>',
            }));
        }

        // Create the carousel
        this.carousel = new Ext.Carousel({
            id: 'carousel',
            defaults: {
                cls: 'card'
            },
            items: pages,
        });

        this.items = [this.carousel, this.postSinglePanel];

        App.views.PostSingleView.superclass.initComponent.call(this);
    },


});

I'm building a Wordpress site using Sencha Touch. I've created a plugin that converts the posts to JSON for the application to read.

In the Applications "Post View" I am loading post information (Title, Body, etc) and I would like to have a carousel that displays all the images within the array "images" I've put through the json within the post.

My application is using the MVC structure (because I like the feeling of my teeth being pulled) and so I need a list of posts to pass the data through onto the Single Posts panel, then get the Images array into the carousel.

The goal is to select a post from the list, load the data into the postsingleview (currently working) and then load the images from that post into the carousel.

Any and all suggestions much appreciated.

Here's what I have so far:

JSON: http://pastie.org/2497239 (Stack's codewrapper wouldn't let me display json, here's the pastebin)

PostListView:

App.views.PostListView = Ext.extend(Ext.Panel, {

    postStore: Ext.emptyFn,
    postList: Ext.emptyFn,
    id:'postlistview',
    layout: 'card',

    initComponent: function () {

        this.postList = new Ext.List({
            store: App.stores.postStore,
            grouped: true,
            emptyText: '<div style="margin:5px;">No notes cached.</div>',
            onItemDisclosure: true,
            indexBar: true,
            itemTpl: '<div class="list-item-title">{title}</div>',

        });

        this.postList.on('disclose', function (record) {
            this.onViewPost(record);
        }, this),

        this.items = [this.postList];

        App.views.PostListView.superclass.initComponent.call(this);
    },

    onViewPost: function (record) {

        Ext.dispatch({
            controller: App.controllers.masterController,
            action: 'viewpost',
            record: record,
        });
    },

});

Master Controller with "ViewPost" action:

    'viewpost': function (options) {

        App.views.postSingleView.bodycard.update(options.record.data);
        App.views.postSingleView.funfactcard.update(options.record.data);
        App.views.postSingleView.crosscard.update(options.record.data);
        App.views.postSingleView.historycard.update(options.record.data);
        App.views.postSingleView.architectcard.update(options.record.data);
        App.views.postSingleView.commentcard.update(options.record.data);
        App.views.postSingleView.dealscard.update(options.record.data);

        App.views.postView.setActiveItem(
            App.views.postSingleView,
            { type: 'slide', direction: 'left' }
        );
    },

Post Single View (Which displays the data from the post)

App.views.PostSingleView = Ext.extend(Ext.Panel, { 

    title:'Single Post',
    id:'postsingleview',
    layout:{
        type:'vbox',
        align:'stretch',
        pack:'end'
    },
    defaults: { flex: 1 },

    initComponent: function () {

        this.bodycard = new Ext.Component({
            title:'Info',
            scroll:'vertical',
            cls : 'card bottomcard card3',
            iconCls:'info',
            tpl: '<tpl for=".">' + 
                    '<div id="bottomcard-container">{body}</div>' +
                 '</tpl>',
        });

        [... There are 7 Ext.Components, but I want to keep it short so I'm deleting them for Display on Stack ]


        this.postSinglePanel = new Ext.TabPanel({
            dock:'bottom',
            id:'singlepost-bottompanel',
            items:[ 
                this.bodycard, 
                this.funfactcard, 
                this.crosscard, 
                this.historycard, 
                this.architectcard, 
                this.commentcard, 
                this.dealscard, 

            ],
            tabBar:{
                dock:'bottom',
                scroll:'horizontal',
                layout:{
                    pack:'center',
                },
            },
        });


        var numberOfPages = 4;
        // Create pages for the carousel
        var pages = [];
        for (var i=0; i<numberOfPages; i++) {
            pages.push(new Ext.Component({
                id: 'page'+i,
                cls: 'page',
                tpl: '<tpl for=".">{body}</tpl>',
            }));
        }

        // Create the carousel
        this.carousel = new Ext.Carousel({
            id: 'carousel',
            defaults: {
                cls: 'card'
            },
            items: pages,
        });

        this.items = [this.carousel, this.postSinglePanel];

        App.views.PostSingleView.superclass.initComponent.call(this);
    },


});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

享受孤独 2024-12-10 12:28:39

我认为 就是你所需要的。

基本上,其想法是在商店完成加载数据后手动添加轮播项目。

这是创建轮播并填充商店中的商品的基本代码。
这个具体示例适用于图片库:

myApp.views.ImageGallery = Ext.extend(Ext.Panel,{

layout: {
    type: 'fit'
},

initComponent: function() {

    this.setLoading(true,true);

    var proxyUrl = 'my_url'

    var store = new Ext.data.Store({
        panel: this,
        model: 'myModel',
        proxy: {
            type: 'ajax',
            url: proxyUrl,
            reader: {
                type: 'json'
            }
        },
        listeners: {
            single: true,
            datachanged: function(){
                var items = [];
                store.each(function(rec){
                    items.push({
                        html: '<img class="myImage" src=' + rec.get('imageUrl') + '>'
                    });
                });

                var carousel = new Ext.Carousel({
                    cardSwitchAnimation: 'slide',
                    layoutOnOrientationChange: true,
                    ui: 'light',
                    items: items,
                    style: 'background: #000',
                    itemId: 'carousel'


                });

                this.panel.setLoading(false);
                this.panel.add(carousel);

                this.panel.doLayout();
            }

        }



    });
    store.read();
    myApp.views.ImageGallery.superclass.initComponent.call(this);
}});

I think that this is what you need.

Basically the idea is to manually add the carousel items after the store has finished loading the data.

Here is a basic code for creating a carousel and populating the items from a store.
this specific example is for an image gallery:

myApp.views.ImageGallery = Ext.extend(Ext.Panel,{

layout: {
    type: 'fit'
},

initComponent: function() {

    this.setLoading(true,true);

    var proxyUrl = 'my_url'

    var store = new Ext.data.Store({
        panel: this,
        model: 'myModel',
        proxy: {
            type: 'ajax',
            url: proxyUrl,
            reader: {
                type: 'json'
            }
        },
        listeners: {
            single: true,
            datachanged: function(){
                var items = [];
                store.each(function(rec){
                    items.push({
                        html: '<img class="myImage" src=' + rec.get('imageUrl') + '>'
                    });
                });

                var carousel = new Ext.Carousel({
                    cardSwitchAnimation: 'slide',
                    layoutOnOrientationChange: true,
                    ui: 'light',
                    items: items,
                    style: 'background: #000',
                    itemId: 'carousel'


                });

                this.panel.setLoading(false);
                this.panel.add(carousel);

                this.panel.doLayout();
            }

        }



    });
    store.read();
    myApp.views.ImageGallery.superclass.initComponent.call(this);
}});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文