0
我遇到了下面創建的tfield []數組的問題。我用六個單元格創建了十行。每個單元都有一個用於驗證的偵聽器。我需要對每行進行計算,合計單元格並創建一個總計。當我調用一個例程來求和單元格時,我的單元格變量tfield [x] .value可能是空白的或未定義的,這取決於我最初聲明tfield []的位置。鈦的範圍問題
function createRow1(i) // start create row
{
row1 = Ti.UI.createView({
backgroundColor: 'white',
borderColor: '#bbb',
borderWidth: 1,
width:'100%', height: 70,
top: 0, left: 0 });
var tfield1 = [];
var label1 = [];
var label2 = [];
for (i=0;i<6;i++)
{
tfield1[i] = Ti.UI.createTextField(baseAttrs);
label1[i] = Ti.UI.createLabel(lbAttrs1);
label2[i] = Ti.UI.createLabel(lbAttrs2);
}
tfield1[0].addEventListener('change', function()
{
if (tfield1[0].value > 10)
{
tfield1[0].value = "";
showMessageTimeout("More than 10.",15);
}
});
// 6 listeners created, one for each element in the
// tfield[] array. Omitted for brevity.
tfield1[0].left ="0%";
tfield1[1].left ="12%";
tfield1[2].left ="24%";
tfield1[3].left ="36%";
tfield1[4].left ="48%";
tfield1[5].left ="60%";
for (i=0;i<6;i++)
{
row1.add(tfield1[i]);
row1.add(label1[i]);
row1.add(label2[i]);
}
return row1;
} /// end of createrow1
for(i = 0; i < 10; i++){
row1 = createRow1(i);
scrollView1.add(row1);
}
/*
all six rows are added to a scrollview. A button
click fires a listener that sums each row which
should also calc a running total of all rows. When
called the calc function either shows tfield[]
as undeclared or as a blank, depending on
where tfield[] is declared.
*/
這很有趣:)我回應了一個請求,每個帖子分成一個問題與較小的代碼。希望我會等待! – Jocala
我用多維數組的更新代碼創建了一個新問題。再次感謝推針。 – Jocala
嗨Jocala,我找不到你提到的問題,你能給我提供一個鏈接嗎?你還有其他3個問題需要幫助嗎?你很好 – kabomi