【问题标题】:Sencha Touch - List/nestesList with imagesSencha Touch - List/nestesList 与图像
【发布时间】:2011-07-25 16:12:46
【问题描述】:

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

如果我像这样创建一个nestedList:

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,但这只是给了我一个空白项。尽管有“文本”属性,但我找不到任何关于如何操作列表项的信息。我知道这是可能的,因为我看到了一个示例,其中包含带有联系人照片的联系人列表。

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

【问题讨论】:

  • 您能否发布一个当前工作示例,说明您目前拥有的内容

标签: image sencha-touch extjs nested-lists


【解决方案1】:

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

您可以将任何您想要的 HTML 添加到列表 itemTpl,这样您就可以在其中添加您的图片。

下面的示例来自sencha api docs,我对其进行了修改以使用图像来让您了解如何添加它们。

希望有帮助!

代码片段

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();
    }
});

【讨论】:

  • 这是一个很好的答案.. 但是..为什么不能在嵌套列表上实现相同的效果???你知道如何将图像和其他 html 组件添加到嵌套列表项吗???请帮忙!!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-03
  • 1970-01-01
相关资源
最近更新 更多