对于模糊/不清楚的标题感到抱歉,但是我想不出一条线说它是'有点头衔。我的问题是我将数据库中的数据加载到多个数组中。使用forloop,我使用以下代码创建了几个按钮:
productButtons[i] = Titanium.UI.createView({
width:"100%",
height:"90",
top:90*i,
link:positionInArray,
backgroundImage:"/images/menu/itemBackground.png",
backgroundSelectedImage:"/images/menu/itemBackground-over.png"
});
productButtons[i].addEventListener('click', function(e) {
var productLocation = {link:e.source.link};
var productScrn = Alloy.createController('product',productLocation).getView();
productScrn.open();
});
我已经在某处读过您可以创建自定义变量并将其添加到视图中,就像我上面的“链接”一样。因此,当单击按钮(或视图)时,我尝试通过使用e.source.link将其存储在productLocation var中来检索视图的链接。
我使用:
捕获productScrn中传递的varvar args = arguments[0] || {};
var productLocation = args.link;
但是当我在新打开的屏幕中记录或警告新的productLocation变量时,10次中有9次返回undefined。这怎么可能?我已经测试了替换e.source.link以获得一个似乎有效的数字。那么我在createView中的自定义变量是不正确的?
干杯!