Angularjs - 检查文件是否作为对象属性存在

时间:2016-07-07 11:21:03

标签: angularjs cordova ionic-framework

我有一个对象数组,如下所示:

$scope.tracks = [
            {
                url: 'https://ionic-audio.s3.amazonaws.com/Message%20in%20a%20bottle.mp3',
                artist: 'The Police',
                title: 'Message in a bottle',
                art: 'https://ionic-audio.s3.amazonaws.com/The_Police_Greatest_Hits.jpg'
            },
            {
                url: 'https://ionic-audio.s3.amazonaws.com/Roxane.mp3',
                artist: 'The Police',
                title: 'Roxane',
                art: 'https://ionic-audio.s3.amazonaws.com/The_Police_Greatest_Hits.jpg'
            }
        ];

我喜欢属性'url'是一个返回本地文件的方法,如果它存在于我的文件夹中,或者url是不存在的文件。

我试过了:

$scope.tracks = tracksFromServer.map(function(track) {
                    return {
                        title: track.title,
                        url: $cordovaFile.checkFile(cordova.file.dataDirectory, track.file).then(function (success) {
                    return cordova.file.dataDirectory + track.file;

                    console.log("file : " + track.url + " was found in phone");
                }, function (error) {
                    return track.url;

                    console.log("file : " + track.url + " not in phone")
                }),
                        artist: track.artist,
                        file: track.file
                    }
                });

但它不起作用

0 个答案:

没有答案