javascript - Appcelerator Titanium(合金)- 打开另一个包含新窗口的 Controller

标签 javascript controller window titanium appcelerator

我正在尝试打开另一个包含新窗口的 Controller ,但是该窗口没有显示。

这是我在 index.js 中创建 Controller 的调用:

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.open();而不是$.uploader.open;

关于javascript - Appcelerator Titanium(合金)- 打开另一个包含新窗口的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20358785/

相关文章:

asp.net-mvc - ASP.NET MVC,将模型从 View 传递到 Controller

c# - 当窗口不再位于顶部时的 WPF 事件

c++ - MFC:如何创建带有透明 PNG 作为背景(而不是窗口镶边)的 Skinnied Dialog?

javascript - Knockout + 大数据集性能

javascript - SVG - 沿着鼠标位置的固定圆移动一个点

javascript - CSS 在表格单元格中旋转内容并调整高度

javascript - 合并两个多维数组,但不能使用 datetime 进行复制

返回函数期间创建的 Javascript 变量

windows - 更改(可能最大化的)窗口的最大尺寸?

grails - 如何在 Grails 中更改 Controller 名称 URL?