【发布时间】:2014-03-13 10:04:48
【问题描述】:
错误 在应用中找不到索引行
我正在处理这个代码
-
如果我单击第一次时间表视图行,它将显示错误
但它会显示子行。
2.如果我单击子行,则会显示此错误:未定义不是对象
(评估(e.row.sub.length)
为什么会出现这个错误?
代码
var win = Ti.UI.createWindow(); var container = Ti.UI.createView({ backgroundColor: "white", layout: "vertical" }); var layout = [{ title: "Parent 1", isparent: true, opened: false, sub: [ { title: "Child 1" }, { title: "Child 2" } ] }, { title: "Parent 2", isparent: true, opened: false, sub: [ { title: "Child 3" }, { title: "Child 4" } ] }]; var tableView = Ti.UI.createTableView({ style: Titanium.UI.iPhone.TableViewStyle.GROUPED, top: 0, height: Ti.Platform.displayCaps.platformHeight, data: layout }); tableView.addEventListener("click", function (e) { var i; //Is this a parent cell? console.log(e.row); if (e.row.isparent) { //Is it opened? if (e.row.opened) { for (i = e.row.sub.length; i > 0; i = i - 1) { tableView.deleteRow(e.index + i); } e.row.opened = false; } else { //Add teh children. var currentIndex = e.index; for (i = 0; i < e.row.sub.length; i++) { tableView.insertRowAfter(currentIndex, e.row.sub[i]); currentIndex++; } e.row.opened = true; } } }); container.add(tableView); win.add(container); win.open();任何帮助将不胜感激
【问题讨论】:
标签: ios titanium titanium-mobile