2013-07-04 58 views
0

我想控制檯記錄從我的xml顯示的所有標籤文本值,這就是我如何記錄標籤Ti.API.info($。label.getText() ); ,但這段代碼似乎不起作用,因爲這隻適用於來自變量的單個值。我如何去做這件事?對不起,太不夠了。謝謝!Titanium Alloy從xml中獲取所有標籤文本值

<TableView id="table" dataCollection="person"> 
    <TableViewRow id="row"> 
    <Label id="label" text="{name}"></Label> 
    </TableViewRow> 
</TableView> 
+2

人在這個社會是有幫助的,但它是很好的做法,以迴應和/或要求更長時間才能接受答案http://stackoverflow.com/questions/17419483/titanium-delete-tableviewrow-model-view-binding-should-automatically-reflect-ta/17425253#comment25332406_17425253 –

+0

當然,謝謝:) –

回答

2

從Appcelerator的文檔http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_Data_Binding

的DataTransform:指定一個可選的回調來格式化模型屬性。傳遞的參數是一個模型,返回值是作爲JSON對象的修改模型。

<TableView id="table" dataCollection="person" dataTransform="dumpText" > 
    <TableViewRow id="row"> 
    <Label id="label" text="{name}"></Label> 
    </TableViewRow> 
</TableView> 

因此,我們可以用這個方法來轉儲任何被添加到列表中

function dumpText(model) { 
    // model to a JSON object 
    var o = model.toJSON(); 
    Ti.API.info(o.name); 
    return o; 
} 
+0

這個作品,非常感謝你亞倫竭盡全力幫助我。保持 :) –