2016-04-20 9 views
0

ListViewには、ItemTapイベントが機能しません。NativeScript、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

こんにちは - itemTap関数をエクスポートしたコードビハインドを提供してください。問題システムでは、その関数の簡単な例を掲載しました。 https://github.com/NativeScript/NativeScript/issues/1995 –

答えて

2

あなたはあなたのコードでエクスポートlistViewItemTapを持っていることを確認することができます。 私は次のことを試してみましたし、[OK]を動作するように思われている:

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の場合と同様にosted) - ページのコードビハインドにイベントハンドラを提供する必要があります。
  • がバインディング(itemTap="{{ listViewItemTap }}")を使用してである場合、あなたのbindingContextオブジェクトにイベントハンドラを提供する必要があります。
+0

ありがとうございます。 このサンプルは動作しています。 私が覚えておきたいことは、プロジェクトになぜpulltorefreshプラグインを統合したのですが、なぜそれが機能していないのかを確認したいのですか? –

関連する問題