Good afternoon everyone, I have already asked a similar question two or three weeks back here, but I could not solve the problem in that way. This problem looks like this: using the phonegap - getMetadata()
function phonegap - getMetadata()
I get the data from the function. The code looks like this:
entry.getMetadata(lastFileModDate, fail); //lastFileModDate функция которая выводит дату
The getMetadata
method gets the name of the function " lastFileModDate
", then creates the " metadata
" object and calls the lastFileModDate
function, passing this object. This function looks like this:
function lastFileModDate(metadata) { console.log(metadata.modificationTime); }
A simple assignment of a variable gives nothing undefined
so I appeal to you, people. I tried many different methods, none of them came up.
Here is the function in which everything is going on:
function listResults(entries) { entries.forEach(function (entry) { //.... var a; function lastFileModDate(metadata) { console.log(metadata.modificationTime); a = metadata.modificationTime; } entry.getMetadata(lastFileModDate, fail); //Отправка функции lastFileModDate console.log(a); //undefined }
How do I get the data that comes in lastFileModDate (metadata)?
//проверяем готов ли девайс к использованию document.addEventListener("deviceready", onDeviceReady, false); //та же проверка function onDeviceReady() { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail); } //массив списка файлов function toArray(list) { return Array.prototype.slice.call(list || [], 0); } //смотрим всем папки function onFileSystemSuccess(fileSystem) { var dirReader = fileSystem.root.createReader(); var entries = []; var readEntries = function () { dirReader.readEntries(function (results) { if (results.length) { entries = entries.concat(toArray(results)); listResults(entries); } }, fail); }; readEntries(); } //какую папку открывать function onFileSystemSuccess(fileSystem) { fileSystem.root.getDirectory(fileListDir, { //адрес к папке create: true, exclusive: false }, getDirSuccess, fail); } //если папка существует то открываем и входим в неё function getDirSuccess(dirEntry) { var directoryReader = dirEntry.createReader(); directoryReader.readEntries(listResults, fail); } var gStr = ''; //посылаем список файлов и папок и сами файлы function listResults(entries) { entries.forEach(function (entry) { if (entry.isDirectory) { gStr += 'dir_' + dir_i + '=' + entry.name + " "; dir_i++; } else { //последняя дата редактирования файла function lastFileModDate(metadata) { //console.log(metadata.modificationTime); modTime = metadata.modificationTime; } //размер файла function fileSize(file) { //console.log(file.size); fSize = file.size; } entry.getMetadata(lastFileModDate, fail); console.log(modTime); entry.file(fileSize, fail); gStr += 'file_' + file_i + '=' + entry.name + ' date_file_' + file_i + '=' + +' file_size_' + file_i + '=' + fSize + " | "; file_i++; } }); //если файл тогда -> if (itm.locname.isFile) { //КИДАЕМ ФАЙЛЫ } else { //посылаем нас сервер сами файлы /*$.post(task_url + "/" + userfotos, gStr, function(data) { //alert("Data Loaded: " + data); } );*/ //console.log(gStr); console.log(gStr); } } //если не получилось function fail(evt) { console.log("Error " + evt.target + evt.error + evt.code); } //если получилось function win(r) { console.log("success"); console.log("Sent = " + r.bytesSent); }