Customizing HTML for the List view cell

二次信任 提交于 2019-12-11 18:09:28

问题


A cell of my Sencha touch list view appears as follows;

But, i want the text to display on the side as shown in the following image. How can i do this. My code looks like this :

<div><img src="{IMAGE_URL}" height="55" width="55"/></div>
{MAIN} <br/>
{SUBMAIN}

I need the following in my list view cell:

1.) I want to add a background colour White.

2.) I want to add a button, where i could click and display an alert.


回答1:


Try my code and you can use this to build on

    var list = { xtype: 'list',
        id: 'list_product',
        emptyText: '<div class="list-empty-text">No hay coincidencias</div>',
        data: [
            {IMAGE_URL: "t1", MAIN: "Test1", SUBMAIN : "test sub1", COST : "30" }, 
            {IMAGE_URL: "t2", MAIN: "Test2", SUBMAIN : "test sub2", COST : "40" }],
        itemTpl: new Ext.XTemplate(
        '<tpl for=".">',
        '<div class = "details">',
            '<div class="maindetails">',
               '<img src="{IMAGE_URL}" align="top" class="textmiddle"/>',   
                '<div class="maincontent">',
                    '<p>{MAIN}</p>',
                    '<p>{SUBMAIN} <span class="x-button btn">${COST}</span></p>',
                '</div>',
            '</div>',
        '</div>',           
        '</tpl>'
        ),
        listeners: [
            {
            element: 'element',
            delegate: 'span.x-button.btn',
            event: 'tap',
            fn: function() {
                alert('handle button');
            }
        } 
        ]
    };

css

please note that following css works.. but you can write better than this to get same output and i am still learning css

.details img {
    width: 50px;
    height: 50px;
}

.maindetails .maincontent{
    margin-top : -50px;
    margin-left : 70px;
}

.btn {
    width : 45px;
    float : right;
}



回答2:


in your css file, set image as inline. And, do the same for the text afterwards.

img {
  display:inline;
}

I think this should solve the problem of displaying text next to the image. Then you could give the image margins so as to improve the looks.

You can use

<input type="button" name="button" value="Press this for alert"> 

for creating a button.



来源:https://stackoverflow.com/questions/17598870/customizing-html-for-the-list-view-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!