Sencha Touch - 带有图像的列表/nestesList

发布于 2024-11-26 15:05:37 字数 1362 浏览 3 评论 0原文

我今天早上开始使用 Sencha Touch,我需要一些帮助。

如果我创建一个像这样的嵌套列表:

var data = {
    text: 'Groceries',
    items: [{
        text: 'Ninja',
        items: [{
            text: 'Water',
            items: [{
                text: 'Sparkling',
                leaf: true
            },{
                text: 'Still',
                leaf: true
            }]
        },{
            text: 'Coffee',
            leaf: true
        },{
            text: 'Espresso',
            leaf: true
        },{
            text: 'Redbull',
            leaf: true
        },{
            text: 'Coke',
            leaf: true
        },{
            text: 'Diet Coke',
            leaf: true
        }]
    }],{
        text: 'Fruit',
        items: [{
            text: 'Bananas',
            leaf: true
        },{
            text: 'Lemon',
            leaf: true
        }]
    },{
        text: 'Snacks',
        items: [{
            text: 'Nuts',
            leaf: true
        },{
            text: 'Pretzels',
            leaf: true
        },{
            text: 'Wasabi Peas',
            leaf: true
        }]
    },{
        text: 'Empty Category',
        items: []
    }]
};

如何将图像添加到列表中?例如,如果我想在减肥可乐旁边有可口可乐标志。我尝试设置 html 里面有一个图像,但这只是给了我一个空白项目。尽管有“文本”属性,但我找不到任何有关如何操作列表项的信息。我知道这是可能的,因为我看到了一个包含带有联系人照片的联系人列表的示例。

我希望你能帮助我并提前谢谢你。

I've started working with Sencha Touch this morning and I could use some help.

If I create a nestedList like this:

var data = {
    text: 'Groceries',
    items: [{
        text: 'Ninja',
        items: [{
            text: 'Water',
            items: [{
                text: 'Sparkling',
                leaf: true
            },{
                text: 'Still',
                leaf: true
            }]
        },{
            text: 'Coffee',
            leaf: true
        },{
            text: 'Espresso',
            leaf: true
        },{
            text: 'Redbull',
            leaf: true
        },{
            text: 'Coke',
            leaf: true
        },{
            text: 'Diet Coke',
            leaf: true
        }]
    }],{
        text: 'Fruit',
        items: [{
            text: 'Bananas',
            leaf: true
        },{
            text: 'Lemon',
            leaf: true
        }]
    },{
        text: 'Snacks',
        items: [{
            text: 'Nuts',
            leaf: true
        },{
            text: 'Pretzels',
            leaf: true
        },{
            text: 'Wasabi Peas',
            leaf: true
        }]
    },{
        text: 'Empty Category',
        items: []
    }]
};

How can I add images to the list? For example if I wanted to have the Coca Cola Logo next to the string diet coke. I tried setting html whith an image inside but that just gave me a blank item. I can't find anything on how to manipulate list items despite the "text" property. I know it's possible though because I saw an example containing a contact list with contact photos.

I hope you can help me and thank you in advance.

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

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

发布评论

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

评论(1

温馨耳语 2024-12-03 15:05:37

您可以向 Ext.regModel 添加额外的字段,因此您需要添加一个字段来保存图像的路径。

您可以将任何您想要的 HTML 添加到列表 itemTpl 中,以便您可以在其中添加图像。

下面的示例来自 sencha api 文档,我将其修改为使用图像让您了解如何添加它们。

希望有帮助!

代码片段

Ext.setup({
    icon: 'icon.png',
    glossOnIcon: false,
    onReady: function() {

        Ext.regModel('Contact', {
            fields: ['firstName', 'lastName', 'imgURL']
        });

        var store = new Ext.data.JsonStore({
            model: 'Contact',
            sorters: 'lastName',

            getGroupString: function(record) {
                return record.get('lastName')[0];
            },

            data: [{
                firstName: 'Tommy',
                lastName: 'Maintz',
                imgURL: 'myImage.png'
            }, {
                firstName: 'Rob',
                lastName: 'Dougan',
                imgURL: 'myImage.png'
            }, {
                firstName: 'Ed',
                lastName: 'Spencer',
                imgURL: 'myImage.pngg'
            }, {
                firstName: 'Jamie',
                lastName: 'Avins',
                imgURL: 'myImage.png'
            }]
        });

        var list = new Ext.List({
            fullscreen: true,

            itemTpl: '<img src="{imgURL}" width="20" heigh="20"></img><span>{firstName} {lastName}</span>',
            //grouped : true,
            //indexBar: true,

            store: store
        });
        list.show();
    }
});

You can add extra fields to your Ext.regModel, so you want to add one to hold the path to you image.

You can add any HTML you want to the lists itemTpl so you can add your image in there.

The example below is from the sencha api docs, I modified it to use images to give you an idea of how you can add them.

Hope that helps!

CODE SNIPPET

Ext.setup({
    icon: 'icon.png',
    glossOnIcon: false,
    onReady: function() {

        Ext.regModel('Contact', {
            fields: ['firstName', 'lastName', 'imgURL']
        });

        var store = new Ext.data.JsonStore({
            model: 'Contact',
            sorters: 'lastName',

            getGroupString: function(record) {
                return record.get('lastName')[0];
            },

            data: [{
                firstName: 'Tommy',
                lastName: 'Maintz',
                imgURL: 'myImage.png'
            }, {
                firstName: 'Rob',
                lastName: 'Dougan',
                imgURL: 'myImage.png'
            }, {
                firstName: 'Ed',
                lastName: 'Spencer',
                imgURL: 'myImage.pngg'
            }, {
                firstName: 'Jamie',
                lastName: 'Avins',
                imgURL: 'myImage.png'
            }]
        });

        var list = new Ext.List({
            fullscreen: true,

            itemTpl: '<img src="{imgURL}" width="20" heigh="20"></img><span>{firstName} {lastName}</span>',
            //grouped : true,
            //indexBar: true,

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