no continuar con la ejecución hasta haber descargado un archivo
Publicado por david (2 intervenciones) el 08/01/2013 14:19:38
asincronia de javascript
quisiera que hasta que no se baja el fichero menu14.txt no continuara.
quisiera que hasta que no se baja el fichero menu14.txt no continuara.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//var MasterView = require('ui/common/MasterView');
//var DetailView = require('ui/common/DetailView');
function getfile(url, file) {
Titanium.API.log("entra en get file");
var archivos = "";
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, file);
var xhr = Ti.Network.createHTTPClient({
onload : function(e) {
f.write(this.responseData);
//return self;
//ficheros.pop(file);
//Titanium.API.log("Numero de ficheros acabado de bajar=" + ficheros.length);
},
onerror : function(e) {
//alert("error=" + url);
Ti.API.log(e.error);
Ti.API.debug(e.error);
},
//timeout : 10
});
xhr.open("GET", url);
xhr.send();
}
function recorreFichero(array) {
for (var actual in array) {
if ( typeof (array[actual]["image"]) != "undefined") {
Titanium.API.log("entra en bajar imagen=" + array[actual]["image"]);
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, array[actual]["image"]);
if (!file.exists()) {
downloadFicheros(array[actual]["image"]);
}
}
prueba = array[actual]["items"];
recorreFichero(prueba);
}
}
function downloadFicheros(texto) {
file = texto;
url = "http://www.yoescojo.com/carta/" + file;
getfile(url, file);
}
//
function leerFichero() {
var file = "menu14.txt"
var v1 = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, file);
v1 = v1.read();
var v1 = JSON.parse(v1);
return v1;
}
//var TheTable = Titanium.UI.createTableView({});
function ApplicationWindow() {
// Titanium.API.log("inicio");
// //declare module dependencies
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "menu14.txt");
if (!file.exists()) {
//file.deleteFile();
}
downloadFicheros("menu14.txt");
//self=downloadFicheros("menu14.txt",prueba());
self=prueba1();
return self;
};
function ejemplo(){
}
function prueba1(){
var MasterView = require('ui/common/MasterView'),
DetailView = require('ui/common/DetailView');
var self = Ti.UI.createWindow({ title : "Menu", exitOnClose : true, navBarHidden : false,backgroundColor : '#ffffff' });
var json = leerFichero();
recorreFichero(json);
var masterView = new MasterView("principal", json);
apartado = masterView.apartado;
masterView = masterView.self1;
self.add(masterView);
return self;
}
module.exports = ApplicationWindow;
Valora esta pregunta


0