2014-07-19 48 views
0

在我的鈦的應用程序,我必須展示元素的列表,這樣做我用以下幾種觀點:數據收集鈦列表視圖

<Alloy> 
    <Collection src="featuredEvents"/> 
    <Window id="win" class="container" navBarHidden="true" exitOnClose="true" onOpen="showIndicator"> 
     <View id="navView"></View> 
     <ActivityIndicator id="activityIndicator" message="L('loading')" /> 

      <TableView id="featuredEvents" dataCollection="featuredEvents" dataFilter="filterEvents" opacity="0" class="list"> 
       <TableViewRow eventId="{alloy_id}" onClick="showEvent"> 
        <View class="event-wrapper"> 
         <ImageView image="{img}" eventId="{alloy_id}" defaultImage="/img/loading.jpg"/> 
         <View class="eventImageOverlayYellow" eventId="{alloy_id}"> 
          <Label id="eventName" text="{name}" eventId="{alloy_id}" /> 
          <View id="eventTypeContainer" class="iconedLabelBig"> 
           <ImageView image="{icon}" class="iconBig" /> 
           <Label id="eventType" text="{type}" eventId="{alloy_id}" /> 
          </View> 
         </View> 
        </View> 
       </TableViewRow> 
      </TableView> 
    </Window> 
</Alloy> 

它工作正常,但在Android上的表現實在是太差了,所以我想用ListView而不是TableView重寫相同的列表。 這就是我想出了:

<Alloy> 
    <Collection src="featuredEvents"/> 
    <Window id="win" class="container" navBarHidden="true" exitOnClose="true" onOpen="showIndicator"> 
     <View id="navView"></View> 
     <ActivityIndicator id="activityIndicator" message="L('loading')" /> 

      <ListView id="featuredEvents" dataCollection="featuredEvents" dataFilter="filterEvents" opacity="0" class="list"> 
       <ListSection eventId="{alloy_id}" onClick="showEvent"> 
        <ListItem class="event-wrapper"> 
         <ImageView image="{img}" eventId="{alloy_id}" defaultImage="/img/loading.jpg"/> 
         <View class="eventImageOverlayYellow" eventId="{alloy_id}"> 
          <Label id="eventName" text="{name}" eventId="{alloy_id}" /> 
          <View id="eventTypeContainer" class="iconedLabelBig"> 
           <ImageView image="{icon}" class="iconBig" /> 
           <Label id="eventType" text="{type}" eventId="{alloy_id}" /> 
          </View> 
         </View> 
        </ListItem> 
       </ListSection> 
      </ListView> 
    </Window> 
</Alloy> 

我控制器index.js:

function showIndicator(e){} 
$.win.open(); 

當我運行它,我得到了以下錯誤:

Location: 
alloy/controllers/index.js 

Message: 
Uncaught typeError: cannot read property '_transform' of null 

Source: 
title:"undefined" != typeof $model__transform["name"] ? $model._ 

-Is有一個用於合金數據收集的ListView示例?

-任何想法是什麼意思?

回答

1

我一直在努力與ListView今天所以我不是專家,但也許我可以幫助。我閱讀了關於ListView s和TableView s之間差異的文檔:http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.ListView我也從這個問題中得到了一些很好的幫助,這是ListViews合金的幾個例子之一。 Titanium Alloy ListView Nested Model Array of Tags

從在所述第一鏈路的文檔:

ListItem對象未在相同的方法作爲TableViewRow創建。 A ListItem通過將ListDataItem對象的數組傳遞給ListSection來創建。

您不能使用add方法將視圖添加到ListItem,這可以使用TableViewRow完成。要將視圖添加到ListItem,您需要定義一個ItemTemplate,它使用模板屬性綁定到列表數據項。

您無法爲ListItem明確設置屬性或綁定事件。您必須分別使用ListDataItemItemTemplate的屬性字典和ItemTemplateViewTemplate的事件字典來設置它們。

至於你的錯誤,當我試圖像TableRow那樣直接將一個變量傳遞給模板時,我得到了類似的錯誤。相反,我不得不使用額外的屬性填充綁定到寺廟的變量。不知道這是否是建議的,但它的工作。