如何从列表视图点击的项目上下文中获取属性?

时间:2019-02-08 18:11:11

标签: javascript data-binding nativescript

我在母版页中使用列表视图有一个母版详细页。我需要在JavaScript函数中获取被点击项的属性。 到目前为止,我得到了[object object]。我可能会缺少什么?

<ListView row="1" col="0" items="{{ listings }}" itemTap="onItemTap" class="list-group">

<ListView.itemTemplate>

    <GridLayout class="list-group-item" rows="auto" columns="*, auto">
        <Label row="0" col="0" text="{{ title }}" class="list-item-header" />
        <Label row="0" col="1" class="page-icon fa" text="&#xf054;" />
    </GridLayout>
</ListView.itemTemplate>

const viewModel = new observableModule.fromObject({
    listings: info.listings || [],
    processing: info.processing || false
});

function onItemTap(args) {
const view = args.view;
const page = view.page;
const tappedItem = view.bindingContext;

try {
    page.frame.navigate({
            moduleName: "./mylistings/mylisting/mylisting",
            context: tappedItem,
            animated: true,
            transition: {
                name: "slide",
                duration: 200,
                curve: "ease"
            }
        });
}
catch (e) {
    console.error(e);
}
}

function onNavigatingTo(args) {
page = args.object;

const myListing = observableModule.fromObject({
    listings: args.context
});
page.bindingContext = myListing.listings;

console.log(`myListing.listings: ${myListing.listings}`);
}

我尝试过:     const mytitle = myListing.listings.title; 我的标题未定义。

0 个答案:

没有答案