NativeScript在ListView中的ItemTap事件不工作
在NativeScript在ListView中的ItemTap事件不工作,nativescript,Nativescript,在ListView中,ItemTap事件不起作用 <ListView items="{{ menu }}" row="1" itemTap="listViewItemTap" > <ListView.itemTemplate> <GridLayout columns="auto, *"> <Image src="{{ imageURL }}" row="0" cssClass="icon"/>
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>
您能否确保在您的代码中导出了
列表视图项点击
。
我尝试了以下方法,似乎效果不错:
XML:
还有一件事需要注意:
- 如果没有为
事件使用绑定(如您发布的XML中所示),则应该在页面的代码后面提供事件处理程序itemTap
- 如果正在使用绑定(
),则应在bindingContext对象中提供事件处理程序itemTap=“{{{listViewItemTap}}}”
列表视图项tap
。
我尝试了以下方法,似乎效果不错:
XML:
还有一件事需要注意:
- 如果没有为
事件使用绑定(如您发布的XML中所示),则应该在页面的代码后面提供事件处理程序itemTap
- 如果正在使用绑定(
),则应在bindingContext对象中提供事件处理程序itemTap=“{{{listViewItemTap}}}”
<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>
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!");
}