Titanium Desktop 在本地文件系统中找不到图像资源? (Javascript)

发布于 2024-11-24 09:48:23 字数 1583 浏览 6 评论 0原文

我认为这一定是钛桌面独有的问题,因为我无法想象为什么它不起作用。

我有一个函数可以检索用户选择的目录,然后继续显示该目录中的所有文件。然后将两个变量显式添加到 DOM:目录中每个文件的列表项,以及源基于目录 +“\folder.jpg”的 img。

我一生都无法弄清楚为什么 Titanium 找不到“folder.jpg”。这些文件都显示得很好,并且两个“URL”的解析方式相同:

function pickMusicFolder (){
        var win = Titanium.UI.getCurrentWindow();

        win.openFolderChooserDialog(function(folderResponse) {
            var file = Titanium.Filesystem.getFile(folderResponse[0]);
            var listing = file.getDirectoryListing();
            for (var i = 0; i < listing.length; i++) {
                if (listing[i].isDirectory()) {
                    // if the listing is a directory, skip over it
                    continue;
                }
                else {
                    // otherwise, print the filename of the file to the #main content window
                    var songOnList = listing[i].nativePath();
                    var iconOnList = file + "\\folder.jpg";
                    var iconAlbum = iconOnList.replace(/\\/g,"/");
                    var songURL = songOnList.replace(/\\/g,"/");
                    $('#main ul').append('<li><a href="javascript:playSong(\'' + songURL + '\')">' + songURL + '</a></li>');
                    $('#main').append('<img src="' + iconAlbum + '" />');
                }
            }
        });
    };

例如,使用我桌面上当前的目录,Chrome 检查器的输出是:

<img src="C:/Users/Josh/Desktop/All Our Tomorrows End Today/folder.jpg">

我还尝试保留黑斜杠,以及替换空格目录中带有下划线。

有人知道为什么无法找到我的图像吗?

I'm assuming this must be a problem exclusive to Titanium Desktop, as I can't imagine why it's not working.

I have a function that retrieves the user's selected directory and then proceeds to display all files within the directory. Two variables are explicitly then added to the DOM: list items for each file within the directory, and an img whose source is based on the directory + "\folder.jpg".

I cannot for the life of me figure out why the "folder.jpg" cannot be found by Titanium. The files all display perfectly fine, and both "URLs" are parsed identically:

function pickMusicFolder (){
        var win = Titanium.UI.getCurrentWindow();

        win.openFolderChooserDialog(function(folderResponse) {
            var file = Titanium.Filesystem.getFile(folderResponse[0]);
            var listing = file.getDirectoryListing();
            for (var i = 0; i < listing.length; i++) {
                if (listing[i].isDirectory()) {
                    // if the listing is a directory, skip over it
                    continue;
                }
                else {
                    // otherwise, print the filename of the file to the #main content window
                    var songOnList = listing[i].nativePath();
                    var iconOnList = file + "\\folder.jpg";
                    var iconAlbum = iconOnList.replace(/\\/g,"/");
                    var songURL = songOnList.replace(/\\/g,"/");
                    $('#main ul').append('<li><a href="javascript:playSong(\'' + songURL + '\')">' + songURL + '</a></li>');
                    $('#main').append('<img src="' + iconAlbum + '" />');
                }
            }
        });
    };

As an example, using a directory currently on my desktop, the output courtesy of Chrome's Inspector is:

<img src="C:/Users/Josh/Desktop/All Our Tomorrows End Today/folder.jpg">

I've also tried keeping blackslashes, as well as replacing the spaces with underscores in the directory.

Anyone have any ideas why my images can't be located?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文