1
我想打開另一個包含新窗口的控制器,但是窗口不顯示。Appcelerator鈦(合金) - 打開另一個包含新窗口的控制器
這是我在index.js調用創建控制器:
function addSong() {
var uploader = Alloy.createController('uploader');
}
這裏是我的uploader.xml文件:
<Alloy>
<Window class="container" title="Add song:">
<Label id="fileHeader">File:</Label>
<Label id="filePath" />
<Button id="browseButton" onClick="openFileChooser" title="Browse" />
<Label id="songTitleHeader">Song title:</Label>
<TextField id="songTitle" />
<Label id="artistHeader">Artist:</Label>
<TextField id="artistBox" />
<Label id="albumHeader">Album:</Label>
<TextField id="albumBox" />
<Label id="genreHeader">Genre:</Label>
<Label id="genreLabel" />
<Button id="selectGenreButton" onClick="genreButtonListener" title="Select genre" />
<OptionDialog id="genres" title="Select a genre">
<Options>
<Option id="rock">Rock</Option>
<Option id="pop">Pop</Option>
<Option id="rnb">R&B</Option>
<Option id="jazz">Jazz</Option>
<Option id="classical">Classical</Option>
<Option id="newage">New Age</Option>
<Option id="electronica">Electronica</Option>
<Option id="country">Country</Option>
<Option id="disco">Disco</Option>
<Option id="funk">Funk</Option>
<Option id="other">Other</Option>
</Options>
</OptionDialog>
<View id="lowerButtons">
<Button id="cancelButton" onClick="cancel" title="Cancel" />
<Button id="uploadButton" onClick="upload" title="Upload to Cloud" />
</View>
</Window>
</Alloy>
這裏是我的uploader.js文件:
var Cloud = require('ti.cloud');
$.uploader.open;
$.uploadButton.setVisible = false;
var fileSelected;
function openFileChooser() {
var options = {
title : "Select file to upload to cloud...",
types : ['mp3', 'm4a', 'aac', 'wav', 'aif', 'aiff'],
typesDescription : "Audio files",
path : Titanium.Filesystem.getUserDirectory()
};
Ti.UI.openFileChooserDialog(function(filenames) {
fileSelected = filenames[0];
}, options);
$.filePath.text = fileSelected;
}
function genreButtonListener() {
$.genres.addEventListener('click', function(e) {
if (e.index == 0) {
$.genreLabel.text = "Rock";
} else if (e.index == 1) {
$.genreLabel.text = "Pop";
} else if (e.index == 2) {
$.genreLabel.text = "R&B";
} else if (e.index == 3) {
$.genreLabel.text = "Jazz";
} else if (e.index == 4) {
$.genreLabel.text = "Classical";
} else if (e.index == 5) {
$.genreLabel.text = "New Age";
} else if (e.index == 6) {
$.genreLabel.text = "Electronica";
} else if (e.index == 7) {
$.genreLabel.text = "Country";
} else if (e.index == 8) {
$.genreLabel.text = "Disco";
} else if (e.index == 9) {
$.genreLabel.text = "Funk";
} else {
$.genreLabel.text = "Other";
}
});
$.genres.show();
}
function cancel() {
$.uploader.close;
}
if ($.filePath.text !== "" && $.songTitle.value !== "" && $.artistBox.value !== "" && $.albumBox.value !== "" && $.genreLabel.text !== "") {
$.uploadButton.setVisible = true;
}
function upload() {
Cloud.Users.secureLogin({
title : 'Sign In'
}, function(e) {
if (e.success) {
Cloud.Files.create({
name : $.songTitle.value,
file : fileSelected
}, function(e) {
if (e.success) {
var file = e.files[0];
alert('Song successfully uploaded to cloud!');
} else {
alert('File could not be created');
}
});
} else {
alert('Error:\\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
$.uploader.close;
}
這裏是我的uploader.tss文件:
".container": {
backgroundColor:"white",
layout: "vertical"
},
"#fileHeader": {
left: 0,
font: { fontSize: 28 },
color: "black"
},
"#filePath": {
left: 0,
font: { fontSize: 22 },
color: "red"
},
"#artistHeader": {
left: 0,
font: { fontSize: 28 },
color: "black"
},
"#albumHeader": {
left: 0,
font: { fontSize: 28 },
color: "black"
},
"#genreHeader": {
left: 0,
font: { fontSize: 28 },
color: "black"
},
"#lowerButtons": {
layout: "horizontal"
}
有誰知道我在做什麼錯?
也在'$ .uploader.close' – asiviero