android - 具有数据收集功能的 Titanium ListViews

标签 android ios listview titanium titanium-alloy

在我的钛应用程序中,我必须显示元素列表,为此我使用以下 View :

<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>

我的 Controller 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._

-有没有ListView结合合金数据采集使用的例子?

-知道这个错误是什么意思吗?

最佳答案

我今天也一直在努力使用ListView,所以我不是专家,但也许我可以提供帮助。我在这里阅读了有关 ListViewTableView 之间差异的文档:http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.ListView我还从这个问题中得到了一些很好的帮助,这是使用 Alloy 的 ListView 的少数示例之一。 Titanium Alloy ListView Nested Model Array of Tags

来自第一个链接中的文档:

ListItem 对象的创建方法与 TableViewRow 不同。 ListItem 是通过将 ListDataItem 对象数组传递到 ListSection 来创建的。

您无法使用 add 方法将 View 添加到 ListItem,而这可以使用 TableViewRow 来完成。要将 View 添加到 ListItem,您需要定义一个 ItemTemplate,它使用 template 属性绑定(bind)到列表数据项。

您无法显式设置 ListItem 的属性或绑定(bind)事件。您必须使用 ListDataItemItemTemplate 的属性字典以及 ItemTemplateViewTemplate 的事件字典来设置它们>,分别。

至于您的错误,当我尝试将变量直接传递到模板中时,我遇到了类似的错误,就像使用 TableRow 所做的那样。相反,我必须用额外的属性填充绑定(bind)到神庙的变量。不确定是否推荐这样做,但它确实有效。

关于android - 具有数据收集功能的 Titanium ListViews,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24839328/

相关文章:

ios - 在 IOS 中使用自动布局在邻居之间居中 View

android - 使 Android ListView Row 适合它包含的图像,而不是更大

android - 可安装的网络应用程序在 Android 上安装时不使用图标

java - Android、异步、回调和 UI

ios - 我们如何在 Xcode 4.6.1 中使用现有的 iPhone 应用程序代码创建类图?

java - 如何维护自定义 ListView 中每个 EditText 的值

android - 从android中的listview获取选中复选框的文本?

java - Android 编程中 fragment 、 Activity 和布局/菜单 XML 文件之间的关系是什么?

java - Android 6(棉花糖)的 SSLHandshakeException SSLProtocolException

ios - 将 Core Data 对象从 DetailViewController 传递到另一个 View Controller