0

私のプロジェクトは、ビューを持つ製品をリストすることです。製品をクリックすると、別のページに移動してスクロール可能なビューの製品を再表示し、クリックされたビューを最初に表示する必要があります)英語悪い:チタンスクロール可能なビューのインデックス

のは、(コレクションから取得)、これは私のリストであるとしましょう:

<Alloy> 
<Window id="products" onClose="cleanup" title="All products" class="container" > 
    <ScrollView dataCollection="list_products" dataTransform="parse_liste" layout='vertical' id="results" class="resultats"> 
     <View product_id="{ID}" 
      product_photo="{photo}" 
      product_name="{product_name}" lauyout='horizontal' class='heightAuto' width='Ti.UI.FILL' backgroundColor='#eee' bottom='1'> 
      <ImageView touchEnabled="false" left='10' image='{photo}' /> 
      <View touchEnabled="false" layout='vertical' height='Ti.UI.SIZE'> 
       <Label touchEnabled="false" left='100' class='nom' text='{product_name}' /> 
       <Label touchEnabled="false" left='100' class='nom' text='{product_price} €/h' /> 
      </View> 
     </View> 
    </ScrollView> 
    <ActivityIndicator color="white" id="activityIndicator" message="Chargement des candidats ..."/> 
</Window> 

すると、製品に対するクリック(コントローラ):

製品ページ:

var args = $.args; 

function getProfil(){ 
    var products_array = [];  
    var c = ['gray','green','blue','red']; 
    _.each(args, function(item, key, value){ 

     /* Créer la vue */ 
     var product_container = Ti.UI.createView({ 
      id:item.ID, 
      layout:'vertical', 
      backgroundColor:c[Math.floor(Math.random() * c.length)] 
     }); 

     var product_image = Ti.UI.createImageView({ image : item.photo}); 
     var product_name = Ti.UI.createLabel({ 
     text: item.champs_candidat.nom 
    }); 

    product_container.add(product_image); 
    product_container.add(product_name); 
    products_array.push(product_container);  
}); 

    var style = $.createStyle({ 
     classes: ['listeProfiles'], 
     apiName: 'ScrollableView' 
    }); 
    var product_scroller = Ti.UI.createScrollableView({ 
     className: 'listeProfiles', 
     views : products_array, 
     showPagingControl:true 
    }); 
    product_scroller.applyProperties(style); 
    $.product_win.add(product_scroller); 
} 

これらのコードは、ちょうど私が最初に(ページAから)クリックされたビューを表示したい、正常に動作します。

ありがとうございました。

答えて

2

私はあなたがScrollViewのクリックイベントにクリックされたビューキャプチャする必要があると思う:あなたのコードを1として

$.list_products.addEventListener('click', function(e){ 
// e.source will give you the clicked view and will behave like $.VIEW_ID 
// so you can access any property or method of the clicked view using e.source here 

Ti.API.info("Clicked View ID = " + e.source.product_id); 

    if(Alloy.Globals.results){ 
     ///////// GO TO PRODUCT PAGE AND PASS ARGS 
     var xpng = require('xpng'); 
     xpng.openWin(Alloy.CFG.nav, 'product', Alloy.Globals.products); 
    } 
}); 

、あなたはすでに、このプロパティのproduct_idとビューの子 - ビューのタッチを無効にしていますですので、上記の変更されたクリックイベントコードは、ScrollView内でクリックされたビューの正しい製品IDを提供することができます。今

  1. あなたがクリックされたビューのPRODUCT_IDを持っています。
  2. コレクションデータにコードを書いて、そのインデックス を知るproduct_id。
  3. ここScrollableView

のこのプロパティcurrentPageを設定するには、ステップ2からインデックスを使用して、全体的なプロセスの概要です:は、電子を使ってクリックしたビューのをPRODUCT_ID取得

  1. 。ソース
  2. これを使用してくださいproduct_idそのインデックスデータ収集。
  3. 最後に、ステップ2から指数はScrollableViewのcurrentPageにプロパティの値となります。 (それはあなたが製品ページに、このインデックスを渡す方法をあなたの好みです。)
+0

こんにちはのPrashant SAINI、助けてくれてありがとう、私はPRODUCT_IDを得ることができ、私はちょうどデータ収集から今すぐインデックスを取得する方法を疑問に思いますか?私は試しました:\t \t var index = _.findIndex(Alloy.Globals.results、{'product_id':e.source.product_id});それは私にエラーをスローする – user44321

+0

こんにちは、私はテストし、それは働いて、あなたの助けをありがとう。 – user44321

+0

あなたはそれを解決しました。 コレクションのアウトラインを投稿しなかったため、コレクションからインデックスを取得するコードを書くことができませんでした。しかし、私はあなたが私のステップで解決できると思っていました。それは、完全な答えを得ることよりも物事を理解するのに役立ちます(ただし、StackOverFlowは正確な答えを意味します)。 –

関連する問題