没有在钛TableViewRow中显示的项目

时间:2015-03-23 17:32:07

标签: titanium titanium-alloy

我在简单的Titanium Book示例应用中创建了一个变体。
我在附带的Nexus 7上启动应用程序。 应用程序启动,但不显示我的示例数据。 我无法看到导致它失败的原因。

Index.xml如下:

<Alloy>
    <Collection src="item"/> 
    <TabGroup>
        <Tab title="Items" icon="KS_nav_ui.png"> -->
            <Window class="container" title="Items">
                <!-- Add TableView and  TableViewRow -->
                <TableView dataCollection="item">
                    <TableViewRow label="{label}" description="{description}" onClick="showItem"></TableViewRow>
                </TableView>
                <Menu id="menu" platform="android">
                    <MenuItem
                    title="Add book"
                    onClick="addBook"
                    showAsAction="Ti.Android.SHOW_AS_ACTION_IF_ROOM" />
                </Menu>
            </Window>
        </Tab>
        <Tab title="Admin" icon="KS_nav_views.png">
            <Window title="Manage your listings">
                <Label>Table of stuff to manage</Label>
            </Window>
        </Tab>
    </TabGroup>
</Alloy>

Indix.js

var myItems = Alloy.Collections.item;

//Create some sample items so that we have something to style.
//This will eventually grab data from the bootstrap sync method.
var item1 = Alloy.createModel('item', {
            taken_by: 0,
            taken_time: 0,
            label: 'Attivo Maestro',
            creator: 1,
            enabled: 1,
            location: 1,
            description: "Today the Maestro model is the most technologically advanced ski on the market. It represents the big news for skiers looking for maximum performance uphill and downhill. Attivo shock absorber technology makes the difference.",
            created: "2015-02-14 13:19:21",
            image: "http://skitrab.com/upload/products_/158/attivo_skis.jpg",
            price: 1,
            currentPrice: 765,
            topic: 1,
            deleted: 0
        });

myItems.add(item1);
item1.save();

function showItem(event) {
    var selectedItem = event.source;
    var args = {
        label : selectedItem.label,
        description : selectedItem.description
    };
    var Itemview = Alloy.createController("Itemdetails", args).getView();

    if (OS_IOS) {
        $.navGroupWin.openWindow(Itemview);
    }
    if (OS_ANDROID) {
        Itemview.open();
    }
}

function addItem(){
    var myAddItem = Alloy.createController("addItem",{}).getView();
    if (OS_IOS) {
        $.navGroupWin.openWindow(myAddItem);
    }
    if (OS_ANDROID) {
        myAddItem.open();
    }
}
$.index.open();

item.js:

exports.definition = {
    config: {
        columns: {
            "taken_by": "integer",
            "taken_time": "integer",
            "label": "text",
            "creator": "integer",
            "enabled": "integer",
            "location": "integer",
            "description": "text",
            "created": "text",
            "image": "text",
            "price": "integer",
            "currentPrice": "integer",
            "topic": "integrer",
            "deleted": "text"
        },
        adapter: {
            idAttribute: "itemid",
            type: "sql",
            collection_name: "item"
        }
    },
    extendModel: function(Model) {
        _.extend(Model.prototype, {
            // extended functions and properties go here
        });

        return Model;
    },
    extendCollection: function(Collection) {
        _.extend(Collection.prototype, {
            // extended functions and properties go here
        });

        return Collection;
    }
};

对我来说这一切似乎都很好,编译没有任何错误。有一些警告看起来并不相关,但它们是:

[WARN] :   linker: libstlport_shared.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
[WARN] :   linker: libtiverify.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
[WARN] :   linker: libkroll-v8.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
[INFO] :   TiApplication: (main) [308,465] Titanium Javascript runtime: v8
[INFO] :   TiRootActivity: (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
[WARN] :   V8Object: (KrollRuntimeThread) [174,174] Runtime disposed, cannot set property 'userAgent'

它加载到nexus上,出现启动画面,然后应用程序以两个标签开始,但是tab1中没有内容,我认为应该有一个项目标签和描述。

有人有什么想法吗?

由于

1 个答案:

答案 0 :(得分:0)

好的,所以答案很简单。在钛教程中,他们有一个名为Favebooks的例子,书中有一个标题和一个作者。

要在TableViewRow中显示标题,请执行以下操作(在其示例中)

<TableViewRow title="{title}" author="{author}" onClick="showItem"></TableViewRow>

我为了自己的目的修改了这个。我有一个带有标签和描述的项目,将TableViewRow行更改为

似乎很自然
<TableViewRow label="{label}" description="{description}" onClick="showItem"></TableViewRow>

但是,这不起作用,你需要把

<TableViewRow title="{label}" description="{description}" onClick="showItem"></TableViewRow>

似乎书名和TableViewRow标题是两个不同的东西。希望有人帮助......