【发布时间】:2014-04-11 20:31:43
【问题描述】:
使用 Titanium 进行课程。我有一个函数可以提取我的 JSON 数据并创建标签和事件监听器。我需要将这个项目制作成一个与标签相反的表格,但我很难做到这一点并且无法完全弄清楚。这是我的带有标签的工作代码。这只是我的第二门编码课程,因此非常感谢任何耐心和内部提示和技巧!
谢谢大家
Ti.UI.setBackgroundImage("347.png");
var bands = {
"sevenfold": {
"headTitle": "Avenged Sevenfold",
"footTitle": "Orange County Metal Band",
"members": [
{
"name": "M. Shadows",
"info": "Lead Singer. Known for his raspy yet powerful vocals"
},
{
"name": "Synyster Gates",
"info": "Lead guitarist and backup vocalist. Known for technical solos and melodic riffs."
},
{
"name": "Zacky Vengeance",
"info": "Rhythm guitarist and backup vocalist. Capable of tight and fast riffs and harmonizing with lead guitar parts. "
},
{
"name": "Johnny Christ",
"info": "Bassist. Contributes heavy grooves as well as intricate undertones to the rhythm section."
},
{
"name": "Arin Iljey",
"info": "Drummer. New-comer to the band. Filled in for the late Jimmy 'The Rev' Sullivan."
},
]
},
"adtr": {
"headTitle": "A Day To Remember",
"footTitle": "Ocala Based Pop-Punk Band",
"members": [
{
"name": "Jeremey McKinnon",
"info": "Lead Singer. Capable of hitting clean high notes as well as low screams."
},
{
"name": "Neil Westfall",
"info": "Rhythm guitarist and backup vocalist. Plays fast punk inspired rhythm sections while contributing back up screams during live shows."
},
{
"name": "Joshua Woodard",
"info": "Bassist. Contributes to the heavy tones of the rhythm section."
},
{
"name": "Kevin Skaff",
"info": "Lead guitarist and backup vocalist. Plays the melodic section of songs and aids Jeremy with clean vocals both in the studio and on live shows."
},
{
"name": "Alex Shelnut",
"info": "Drummer. Adds fast punk fills with metal influenced double bass beats."
}
]
}
};
var mainWindow = Ti.UI.createWindow({
title: "Band Members",
backgroundImage: "347.png"
});
var navWindow = Ti.UI.iOS.createNavigationWindow({
window: mainWindow
});
var getDetail = function(){
var detailWindow = Ti.UI.createWindow({
title: this.text,
backgroundColor: "white"
});
var detailText = Ti.UI.createLabel({
text: this.details,
top: 30,
left: 15,
right: 15
});
detailWindow.add(detailText);
navWindow.openWindow(detailWindow);
};
var makeUI = function(){
var spacing = 30;
for(n in bands){
var titleLabel = Ti.UI.createLabel({
text: bands[n].headTitle,
left: 30,
right: 30,
borderRadius: 5,
top: spacing,
height: 25,
textAlign: "center",
backgroundColor: "#333",
font: {fontSize: 22, fontFamily: "Verdana", fontWeight: "bold"},
color: "#fafafa"
});
spacing = titleLabel.top + titleLabel.height + 10;
for(m in bands[n].members){
var itemLabel = Ti.UI.createLabel({
text: bands[n].members[m].name,
details: bands[n].members[m].info,
left: 30,
right: 30,
borderRadius: 5,
textAlign: "center",
top: spacing,
height: 25,
backgroundColor: "#ffffff",
font: {fontSize: 22, fontFamily: "Verdana"},
color: "#333"
});
mainWindow.add(itemLabel);
spacing = itemLabel.top + itemLabel.height + 10;
itemLabel.addEventListener("click", getDetail);
}
mainWindow.add(titleLabel);
spacing = itemLabel.top + itemLabel.height + 40;
}
};
makeUI();
navWindow.open();
【问题讨论】:
标签: javascript json titanium