Sencha Touch - 带有图像的List/nestesList

Mat*_*teo 2 extjs image nested-lists sencha-touch

我今天早上开始使用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: []
    }]
};
Run Code Online (Sandbox Code Playgroud)

如何将图像添加到列表中?例如,如果我想在可乐可乐标记旁边放置可口可乐标志.我尝试在里面设置一个html图像,但这只是给了我一个空白项目.尽管有"text"属性,我找不到关于如何操作列表项的任何内容.我知道这是可能的,因为我看到一个包含联系人列表和联系人照片的示例.

我希望你能帮助我,并提前感谢你.

car*_*rok 7

您可以为您添加额外的字段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();
    }
});
Run Code Online (Sandbox Code Playgroud)

  • 这是一个很好的答案..但是..为什么在嵌套列表上不能实现相同的??? 你知道如何将图像和其他html组件添加到嵌套列表项吗?请帮助!!! (2认同)