【问题标题】:appcelerator delete listview row?appcelerator 删除列表视图行?
【发布时间】:2015-03-25 08:10:26
【问题描述】:

我想从 appcelerator (Titanium) 的列表视图中删除一行。

我已经为 tableview 做了很多研究,坏消息是我不能使用 tableview 我的列表中有大量数据,只有 listview 可以处理它们。

我的问题是我找不到通过提供行索引或行对象来从 Android 和 IOS 的列表视图中删除行的方法。

我的代码:

/*
  *  custom tempalte 
  */
 var myTemplate = { childTemplates: [  {   type      : 'Ti.UI.View', 
                                                bindId    : 'groupHead', 
                                                properties: {  // top : '2dp',
                                                                width : '100%',
                                                                height : '55dp',
                                                            },
                                                childTemplates : [ {  type      : 'Ti.UI.View', 
                                                                      bindId    : 'groupHeadc',         
                                                                      properties: { width : '40%',
                                                                                    height : '55dp',
                                                                                    left:'0dp',
                                                                                    backgroundImage:'/imgs/pix.png',
                                                                                    backgroundRepeat:true
                                                                                 },
                                                                      childTemplates : [{  type      : 'Ti.UI.Label', 
                                                                                           bindId    : 'lblGroupTitle',         
                                                                                           properties: {color : '#000000',
                                                                                                        left : '2dp',
                                                                                                        right : '45dp',
                                                                                                        height : Ti.UI.SIZE,
                                                                                                        width:'100%',
                                                                                                        horizontalWrap:true,
                                                                                                        font : {
                                                                                                            fontSize : '14dp',
                                                                                                            fontFamily : customFont
                                                                                                        },
                                                                                                        }
                                                                                          }]
                                                                   },
                                                                   {  type      : 'Ti.UI.View', 
                                                                      bindId    : 'groupc',         
                                                                      properties: { //top : '2dp',
                                                                                    width : '60%',
                                                                                    height : '55dp',
                                                                                    //left:'50%',
                                                                                    right:'0dp',
                                                                                    backgroundImage:'/imgs/pix.png',
                                                                                    backgroundRepeat:true
                                                                                },
                                                                      childTemplates : [{  type      : 'Ti.UI.Label', 
                                                                                           bindId    : 'lblGroupc',         
                                                                                           properties: {color : '#000000',
                                                                                                        left : '2dp',
                                                                                                        right : '45dp',
                                                                                                        height : Ti.UI.SIZE,
                                                                                                        width:'80%',
                                                                                                        horizontalWrap:true,
                                                                                                        font : {
                                                                                                            fontSize : '14dp',
                                                                                                            fontFamily : customFont,
                                                                                                            //LineHeight:'10dp',
                                                                                                        },
                                                                                                      }
                                                                                          }]                                                                                
                                                                    },
                                                                     {    type      : 'Ti.UI.ImageView', 
                                                                          bindId    : 'close',         
                                                                          properties: { height : '16dp',
                                                                                        width : '16dp',
                                                                                        right : '5dp',
                                                                                        image : '/imgs/cross-red.png',
                                                                                        bubbleParent : false
                                                                                    },              
                                                                          events : { click : deleteContact }                                                            
                                                                    }
                                                                  ],
                                               // events : { click: rowClick }
                                            },
                                        ]
                                    };

/*
*  this function listener to delete row from listview is working 
*/
function deleteContact(e)
{

    Ti.API.info("Delete ListView Raw = "+ JSON.stringify(e) );

    var sectionIndex = 0;

    Ti.API.info("Raw = "+ e.itemIndex );

    //not working
    grainSection[sectionIndex].deleteItemsAt(e.itemIndex,1);

}


        grainSection[s] = Ti.UI.createListSection();
    var grainDataSet    = [];
    var sections        = [];

    listviews[l] = Ti.UI.createListView({   templates: { 'template': myTemplate },
                                            defaultItemTemplate: 'template',
                                            width           : "100%",
                                            height          : "100%",
                                         // borderRadius    : 5,
                                            backgroundColor : "transparent",
                                            caseInsensitiveSearch: true
                                        });
    contentView.add(listviews[l] );

【问题讨论】:

    标签: listview titanium row appcelerator


    【解决方案1】:

    在您的 deleteContact 方法中尝试以下操作:

    function deleteContact( e )
    {
    
        Ti.API.info("Delete ListView Raw = "+ JSON.stringify(e) );
        Ti.API.info("Raw = "+ e.itemIndex );
        e.section.deleteItemsAt( e.itemIndex, 1 );
    }
    

    这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-05
      • 2016-05-04
      • 2017-02-21
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多