2

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

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

4

1 回答 1

7

您可以在 中添加额外的字段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();
    }
});
于 2011-07-26T10:48:34.143 回答