2017-12-27 936 views
0

var gestures = require("ui/gestures"); 如何檢測特定的圖像事件自來水

for (var i = 0; i < images.length; i++) { 
     imgArray[i] = new imageModule.Image(); 
    imgArray[i].id = "img"; 
    imgArray[i].width = w/6; 
    imgArray[i].height = h/7; 
    imgArray[i].src = images[i]; 
    imgArray[i].stretch = "fill"; 
    wrap_layout.addChild(imgArray[i]); 
    imgArray[i].on(gestures.GestureTypes.tap, function (args) { 
    console.log("tap"+"|"+i); 
    }); 

這是我的循環添加圖像的陣列WrapLayout上nativescript是做工精良我的問題是我想實現雙擊手勢爲每個圖像是工作,但沒有圖像的不特定指數的任何想法如何解決呢

+0

所以我想你的問題是,登錄不知疲倦x總是圖像的數量? –

+0

是的,經過一段時間的調試後,我發現它的解決方案 – Elmissouri

+0

然後提供解決方案在這裏,並標記自己的答案接受,請;) –

回答

0
var onTap = function (args) { 
console.log('tap'); 
}; 
images = raw_data.split("\n"); 
     for (i = 0; i < images.length; i++) { 
      var m = re.exec(images[i]); 
      idArray[i] = m[0]; 
      images[i] = images[i].replace(idArray[i], ""); 
      imgArray[i] = new imageModule.Image(); 
      imgArray[i].src = images[i]; 
      imgArray[i].stretch = "fill"; 
      stackArray[i] = new StackLayout(); 
      imgArray[i].id = "img"; 
      imgArray[i].width = sw; 
      imgArray[i].height = sh; 
      stackArray[i].id = "stack"; 
      stackArray[i].width = sw; 
      stackArray[i].height = sh; 
      stackArray[i].num = i; 
      stackArray[i].addChild(imgArray[i]); 
      wrap_layout.addChild(stackArray[i]); 
      stackArray[i].on(buttonModule.Button.tapEvent, onTap, this); 
     } 

這是爲我工作