在ListView
中,ItemTap
事件无效。
<ListView items="{{ menu }}" row="1" itemTap="listViewItemTap" >
<ListView.itemTemplate>
<GridLayout columns="auto, *">
<Image src="{{ imageURL }}" row="0" cssClass="icon"/>
<StackLayout col="1">
<Label text="{{ title }}" cssClass="name"/>
<Label text="{{ subtitle }}" cssClass="location"/>
</StackLayout>
</GridLayout>
</ListView.itemTemplate>
</ListView>
答案 0 :(得分:2)
您能否确保在代码中导出listViewItemTap
。
我尝试过以下操作,似乎工作正常:
XML:
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo">
<ListView items="{{ menu }}" row="1" itemTap="listViewItemTap" >
<ListView.itemTemplate>
<GridLayout columns="auto, *">
<Image src="{{ imageURL }}" row="0" cssClass="icon"/>
<StackLayout col="1">
<Label text="{{ title }}" cssClass="name"/>
<Label text="{{ subtitle }}" cssClass="location"/>
</StackLayout>
</GridLayout>
</ListView.itemTemplate>
</ListView>
</Page>
JS:
exports.onNavigatingTo = function(args) {
var page = args.object;
page.bindingContext = {
menu:[
{ imageUrl: "", title: "title 1", subtitle: "subtitle 1"},
{ imageUrl: "", title: "title 2", subtitle: "subtitle 2"},
{ imageUrl: "", title: "title 3", subtitle: "subtitle 3"},
{ imageUrl: "", title: "title 4", subtitle: "subtitle 4"},
]
}
}
exports.listViewItemTap = function() {
console.log("Item tapped!");
}
还有一件事要寻找:
itemTap
事件的绑定(如您发布的XML) - 您应该在页面的代码隐藏中提供事件处理程序。itemTap="{{ listViewItemTap }}"
),则应在bindingContext对象中提供事件处理程序。