【发布时间】:2015-06-28 20:49:08
【问题描述】:
我开发了一个基于以下树结构的应用程序:
默认:
- 类别
- 类别
- 类别
点击类别时:
- 类别
- 子类别
- 产品
- 子类别
类别
类别
有时:
类别
-
类别
- 产品
类别
这里我必须使用 tableview 来实现这个概念。
是的,我创建了 tableview,然后创建了 tableviewsection。我添加了类别 在 tableviewsection.i 中,我在 tableviewsection 中创建了 tableviewrow。如果我点击了选定的类别,我已经在这些 tableviewrow 中添加了子类别值。但是某些具有子类别的类别... 有些类别没有子类别。直接有产品。所以你能解释一下吗
编辑:
我有以下代码:
// create menu view
var data = [];
var v1 = Ti.UI.createView({
height: '100%',
width: '320dp',
left: '0%',
backgroundColor: '#212429'
});
$.drawermenu.drawermenuview.add(v1);
var tableView = Ti.UI.createTableView({
height: '100%',
width: '100%',
separatorColor: '#111214',
allowsSelection: true,
style: Ti.UI.iPhone.TableViewStyle.GROUPED
});
v1.add(tableView);
var dataArray = [];
getCategoryList();
function getCategoryList() {
var sendit = Ti.Network.createHTTPClient({
onerror: function(e) {
Ti.API.debug(e.error);
alert('There was an error during the connection');
},
timeout: 10000,
});
sendit.open('GET', url + 'android_livedev/client/xxx.php?action=allCategory&category=all');
sendit.send();
sendit.onload = function() {
var response = JSON.parse(this.responseText);
if (response[0].success == 0) {
tableView.headerTitle = response[0].message;
} else {
tableView.headerTitle = "";
dataArray = [];
for (var i = 0; i < response[0].data.length; i++) {
var customsection = Ti.UI.createView({
width: Ti.UI.FILL,
height: Ti.UI.SIZE,
opened: true,
id: i,
categorylist_category_id: response[0].data[i].categoryid,
categorylist_level: response[0].data[i].category_level,
backgroundcolor: '#fff',
length: response[0].data.length,
});
var text = Ti.UI.createLabel({
text: response[0].data[i].category,
left: 20,
id: i,
categorylist_category_id: response[0].data[i].categoryid,
categorylist_level: response[0].data[i].category_level,
color: '#000'
});
customsection.add(text);
row = Ti.UI.createTableViewSection({
headerView: customsection,
});
dataArray.push(row);
customsection.addEventListener('click', function(e) {
categorylist_category_id = e.source.categorylist_category_id;
categorylist_level = e.source.categorylist_level;
categorylist_id = e.source.id;
if (categorylist_level == "Y") {
var subcategory = [];
for (j = 0; j < response[0].data[categorylist_id].subcategorymm.length; j++) {
var subcategory = Ti.UI.createTableViewRow({
subcategorylist_category_id: response[0].data[categorylist_id].subcategorymm[j].categoryid,
layout: 'horizontal',
top: 5,
width: "100%",
backgroundcolor: '#000',
height: Ti.UI.SIZE,
});
var subcategorytext = Ti.UI.createLabel({
text: response[0].data[categorylist_id].subcategorymm[j].category,
top: 5,
width: Ti.UI.FILL,
font: {
fontSize: '18dp'
},
color: '#040404',
wordWrap: true,
height: Ti.UI.SIZE,
ellipsize: true
});
subcategory.add(subcategorytext);
};
row.add(subcategory);
} else {
from = "Product";
var product = Alloy.createController('product').getView();
product.open();
}
});
};
tableView.setData(dataArray);
};
};
}
var top10Screen = Alloy.createController('top10Screen').getView();
$.drawermenu.drawermainview.add(top10Screen);
Ti.App.addEventListener('settingImg', function(data) {
$.drawermenu.showhidemenu();
});
$.sample.open();
编辑:
这里给出了合金代码:
sample.xml:
<Alloy>
<Window class="container">
<Require type="widget" src="com.drawermenu.widget" id="drawermenu"/>
</Window>
</Alloy>
我必须打开滑块菜单上的类别。这样我才能使用这些小部件。如果我点击了滑块菜单上的类别,需要在滑块菜单上显示子类别。这正是我的范围。
这正是我的 json:
[
{
"message": "Category list found",
"data": [
{
"categoryid": "335",
"parentid": "0",
"category": "New In",
"description": "",
"meta_description": "",
"avail": "Y",
"order_by": "0",
"product_count": "2",
"top_product_count": "1",
"meta_keywords": "",
"override_child_meta": "N",
"title_tag": "",
"lpos": "1",
"rpos": "4",
"category_level": "Y",
"new_category_images": "https://dev101.example.com/xxx/images/C/newin.png",
"subcategorymm": [
{
"categoryid": "344",
"parentid": "335",
"category": "subcategory-newin",
"description": "",
"meta_description": "",
"avail": "Y",
"order_by": "0",
"product_count": "1",
"top_product_count": "1",
"meta_keywords": "",
"override_child_meta": "N",
"title_tag": "",
"lpos": "2",
"rpos": "3",
"category_level": "N"
}
]
},
{
"categoryid": "336",
"parentid": "0",
"category": "Women's",
"description": "",
"meta_description": "",
"avail": "Y",
"order_by": "1",
"product_count": "2",
"top_product_count": "2",
"meta_keywords": "",
"override_child_meta": "N",
"title_tag": "",
"lpos": "5",
"rpos": "6",
"category_level": "N",
"new_category_images": "https://dev101.example.com/xxx/images/C/women.png"
}
],
"success": "1"
}
]
这里列出了类别。但是,如果单击该类别,它将列出子类别。但是我无法查看子类别。你能检查一下这个并给我一个解决方案吗?
编辑:
在这个for循环中:
for(j=0;j<response[0].data[categorylist_id].subcategorymm.length;j++){
我已经打印了类似的值:
Ti.API.info(response[0].data[categorylist_id].subcategorymm[j].category);
这意味着子类别在我的控制台窗口中打印得很好。但是我无法查看 tableviewrow。我知道我犯了一点错误。所以你能找出错误并给我一个解决方案。
【问题讨论】:
-
请添加合金代码,你有两个
Windows吗?我注意到您将TableView添加到View中,该View也添加到win中,在最后一条语句中,您打开了另一个窗口-->$.sample.open。如果您添加了 URL 字符串也会很有帮助,以便我可以测试您的代码。 -
@Zabady 你能看看我更新的问题并给我一个想法或解决方案
-
@Zabady 你能看看我更新的问题并给我一个想法或解决方案
-
问题是,我还是不能测试你的代码,你能把你的项目上传到github吗?如果可以的话,我会克隆它并尽我所能帮助你:)
-
能否请您添加一些屏幕截图。您是希望它在一个页面上还是在单击表格单元格后,它应该转到另一个页面?
标签: javascript iphone json titanium tableview