如何检测特定图像上的事件点击
how to detect event tap on specific image
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);
});
这个我的循环将图像数组添加到 nativescript 上的 WrapLayout 运行良好我的问题是我正在尝试为每个图像实现点击手势是有效的但没有特定的图像索引不知道如何解决它
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);
}
对我有用
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);
});
这个我的循环将图像数组添加到 nativescript 上的 WrapLayout 运行良好我的问题是我正在尝试为每个图像实现点击手势是有效的但没有特定的图像索引不知道如何解决它
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);
}
对我有用