Text 我无法在钛表中获取文本
我对钛合金很陌生,我必须为学校的一个项目做这个。无论如何,我无法让文本在表格中显示。帮助 这是我的代码:Text 我无法在钛表中获取文本,text,titanium,tableview,Text,Titanium,Tableview,我对钛合金很陌生,我必须为学校的一个项目做这个。无论如何,我无法让文本在表格中显示。帮助 这是我的代码: // resourcesDirectory is actually the default location, so the first // argument could be omitted here. var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "textfile.txt"); var file
// resourcesDirectory is actually the default location, so the first
// argument could be omitted here.
var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "textfile.txt");
var filet1 = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "table1.txt");
var filet2 = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "http://pastebin.com/raw.php?i=JDCZyfw3");
//http://www.google.com/humans.txt
var xhr = Titanium.Network.createHTTPClient();
xhr.open("GET","http://www.google-analytics.com/ga.js");
xhr.onload = function(){
// check status of connection to server
statusCode = xhr.status;
//check the response code returned
if(statusCode == 200)
{
var doc = this.responseText;
//write data from downloaded text file to local text file
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'test.txt');
f.write(doc);
}
};
xhr.send();
//-----------------------------------------------------------------------
//---------------------local file read---------------------------------------
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'test.txt');
// read the file into contents var
//var contents = f.read();
// print out contents of file
//Ti.API.info('contents = ' + contents.text);
//-----------------------------------------------------------------------
//--------------------------end of file read--------------------------
var content = file.read();
var content2 = f.read();
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#DCE6F2');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({
title:"Niveau's",
backgroundColor:'#DCE6F2',
window: win1
});
var header= Titanium.UI.createView({
backgroundImage:'logo.jpg',
//backgroundColor: 'black',
top: 0, left:0,
height:65, width:320
});
//win1.add(header);
var tab3 = Titanium.UI.createWindow({
title:'Leerwegen',
backgroundColor:'#DCE6F2',
window: win3
});
var tab4 = Titanium.UI.createWindow({
title:'Instellingen',
backgroundColor:'#DCE6F2',
window: win4
});
var data = [
{title:'Niveau 2', hasChild:true, dest:'C:\Users\Rick\Documents\Titanium_Studio_Workspace\mbo app pdh\Resources\Car_1.js'},
{title:'Niveau 3', hasChild:true, dest:'C:\Users\Rick\Documents\Titanium_Studio_Workspace\mbo app pdh\Resources\Car_2.js'},
{title:'Niveau 4', hasChild:true, dest:'C:\Users\Rick\Documents\Titanium_Studio_Workspace\mbo app pdh\Resources\Car_3.js'}
];
var table = Ti.UI.createTableView({
data: data
});
table.addEventListener('click', function(e){
if (e.rowData.hasChild) {
var newWin = Ti.UI.createWindow({
url: e.rowData.url,//dest
title: e.rowData.title,
backgroundColor: '#DCE6F2'
});
tab1.open(newWin);
}
});
var view = Ti.UI.createView();
view.add(table);
win1.add(view);
var label1 = Titanium.UI.createLabel({
color:'#999',
text:filet2,
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
var label2 = Titanium.UI.createLabel({
color:'#999',
text: content2,
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'left',
width:'auto'
});
//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({
title:'Domeinen',
backgroundColor:'#DCE6F2'
});
var win3 = Titanium.UI.createWindow({
title:'Leerwegen',
backgroundColor:'#DCE6F2'
});
var win4 = Titanium.UI.createWindow({
title:'Instellingen',
backgroundColor:'#DCE6F2'
});
var tab3 = Titanium.UI.createTab({
title:'Leerwegen',
// backgroundColor:'#DCE6F2',
window:win3
});
var tab4 = Titanium.UI.createTab({
title:'Instellingen',
window:win4
});
var tab2 = Titanium.UI.createTab({
// icon:'KS_nav_ui.png',
title:'Domeinen',
window:win2
});
var tab1 = Ti.UI.createTab({
title: "Niveau's",
window: win1
});
win2.add(label2);
win1.add(label1);
//
// add tabs
//
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tabGroup.addTab(tab3);
tabGroup.addTab(tab4);
tabGroup.open();
这是我的表文件car_3.js
var view_car_3 = Ti.UI.createView();
var label_car_3 = Ti.UI.createlabel({
text: 'lorum ipsum nogwat',
height: 35,
width: 150 ,
top: 120
});
view_car_3.add(label_car_3);
Ti.UI.currentWindow.add(view_car_3);
有人知道如何让文本出现在表niveau 4中吗?首先,而且对于大多数人来说……如果你将所有文件都放在resources文件夹下,那么就不需要给出整个路径……所以一定要遵循
var data = [
{title:'Niveau 2', hasChild:true, dest:'Car_1.js'},
{title:'Niveau 3', hasChild:true, dest:'Car_2.js'},
{title:'Niveau 4', hasChild:true, dest:'Car_3.js'}
];
变量是dest而不是url,所以您需要在表click事件中更改它
table.addEventListener('click', function(e){
if (e.rowData.hasChild) {
var newWin = Ti.UI.createWindow({
url: e.rowData.dest,
title: e.rowData.title,
backgroundColor: '#DCE6F2'
});
欢迎。请记住,我们无法从项目外部访问任何文件,因此每当您需要访问文件时,请仅将其放在项目文件夹下,并根据当前窗口设置路径。