2015-04-14 38 views
1

鈦Appcelerator的 無法對下面的按鈕點擊更新列表視圖代碼內的文本:更新文本上itemClick在鈦Appcelerator的

{ 
      type : 'Ti.UI.View', 
      bindId : 'vwqtySelection', 
      properties : { 
       top : '30dp', 
       height : '50dp', 
       //backgroundColor: 'red', 
       width : require('main').XhdpiSupport(150), 
       right : '90dp', 
       zIndex : 10 

      }, 
      childTemplates : [{ 
       type : 'Ti.UI.Button', 
       bindId : 'btnMinus', 
       properties : { 
        left : '15dp', 
        color : '#676972', 
        title : '-', 
        width : require('main').XhdpiSupport(30), 
        height : require('main').XhdpiSupport(22), 
       } 

      }, { 
       type : 'Ti.UI.Label', 
       bindId : 'qtyValue', 
       properties : { 
        //touchenabled : false, 
        left : '50dp', 
        color : '#676972', 
        text : '4', 
        textAlign : 'center', 
       } 

      }, { 
       type : 'Ti.UI.Button', 
       bindId : 'btnPlus', 
       properties : { 
        left : '79dp', 
        color : '#676972', 
        title : '+', 
       } 
      }] 
     } 

>項目單擊選擇在哪裏更新按鈕,點擊文字 要更新上按鈕文本點擊即4至2

下面代碼我試圖

scrlView.addEventListener('itemclick', function(e) { 

     if (e.bindId === 'btnMinus') { 
      item = section.getItemAt(e.itemIndex); 
       e.section.qtyValue.properties.text = "2"; 
       e.section.updateItemAt(e.itemIndex, item); 
       //here not able to update text 4 to 2 
     } else if (e.bindId === 'btnPlus') { 

     } 
}}; 

誤差得到下面 消息:未捕獲的類型錯誤:無法的未定義

+0

我不明白你的代碼,你如何使用列表視圖以及上面的代碼究竟是做什麼的?無論如何,要更新列表項目中的字段,最簡單的方法是獲取該項目,編輯它,然後在列表視圖中更新它,只需解釋一點你的代碼,我會幫助的,我將添加一個合金如何在'listView'中編輯標籤的例子。 – Zabady

回答

0

這種讀入屬性「屬性」是如何在一個listView編輯UI元素的例子。 每個ListItem都包含一個Label,其中包含一個數字和一個加號標籤,當您單擊加號標籤時,它應該增加該listItem中的號碼。

index.xml文件:

<ListView id="listView" class="listView" defaultItemTemplate="template"> 
    <Templates> 
     <ItemTemplate name="template" layout='horizontal'> 
      <Label bindId="number" id="number" left=20>0</Label> 
      <Label bindId="add" id="add" right=20 onClick="addOneToCurrentNumber">+</Label> 
     </ItemTemplate> 
    </Templates> 

    <ListSection> 
     <ListItem number:text='0' /> 
     <ListItem number:text='-50' /> 
     <ListItem number:text='100' /> 
     <ListItem number:text='1024' /> 
    </ListSection> 
</ListView> 

index.js文件:

function addOneToCurrentNumber(e) { 
    var row = $.listView.sections[0].getItemAt(e.itemIndex); 
    var number = parseInt(row.number.text); 
    number++; 
    row.number.text = number; 
    $.listView.sections[0].updateItemAt(e.itemIndex, row, { animated:true }); 
} 

希望這會有所幫助,請讓我知道如果你需要任何修改。