예 티타늄이이를 수행 할 수 있습니다. 변수가 배열 /리스트/변수 인 경우 Ti.App.myList
과 같은 전역 변수를 사용해야합니다. 이미지 나 데이터베이스와 같이 더 복잡한 데이터를 저장해야하는 경우 내장 파일 시스템을 사용해야합니다. Appcelerator website에는 정말 좋은 문서가 있습니다.
다음과 같이 될 것이다하는 절차 :
- 미래 응용 프로그램 시작시 처음
- 저장하여 원하는 방식으로 데이터 (글로벌 변수를 파일 시스템)
- 에 대한 데이터를로드 로컬 목록/데이터를 읽고 동기화가 성공할 때까지 표시하십시오.
당신은 어떤 업데이트가 네트워크 사용을 최소화 할 필요가 어떠했는지를 확인하려면 몇 가지 변수를 구현하기 위해 고려해야
은 (는 에너지를 절약하고 사용자의 인터넷 연결 속도가 느린 경우 더 나은 사용자 경험을 제공합니다). API 호출의 성공 방법에 배치해야이 코드에 추가
if (response.state == "SUCCESS") {
Ti.API.info("Themes successfully checked");
Ti.API.info("RESPONSE TEST: " + response.value);
//Create a map of the layout names(as keys) and the corresponding url (as value).
var newImageMap = {};
for (var key in response.value) {
var url = response.value[key];
var filename = key + ".jpg"; //EDIT your type of the image
newImageMap[filename] = url;
}
if (Ti.App.ImageMap.length > 0) {
//Check for removed layouts
for (var image in Ti.App.imageMap) {
if (image in newImageMap) {
Ti.API.info("The image " + image + " is already in the local map");
//Do nothing
} else {
//Delete the removed layout
Ti.API.info("The image " + image + " is deleted from the local map");
delete Ti.App.imageMap[image];
}
}
//Check for new images
for (var image in newImageMap) {
if (image in Ti.App.imageMap) {
Ti.API.info("The image " + image + " is already in the local map");
//Do nothing
} else {
Ti.API.info("The image " + image + " is put into the local map");
//Put new image in local map
Ti.App.imageMap[image] = newImageMap[image];
}
}
} else {
Ti.App.imageMap = newImageMap;
}
//Check wether the file already exists
for (var key in response.value) {
var url = response.value[key];
var filename = key + ".png"; //EDIT YOUR FILE TYPE
Ti.API.info("URL: " + url);
Ti.API.info("FILENAME: " + filename);
imagesOrder[imagesOrder.length] = filename.match(/\d+/)[0]; //THIS SAVES THE FIRST NUMBER IN YOUR FILENAME AS ID
//Case1: download a new image
var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "/media/" + filename);
if (file.exists()) {
// Do nothing
Titanium.API.info("File " + filename + " exists");
} else {
// Create the HTTP client to download the asset.
var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
if (xhr.status == 200) {
// On successful load, take that image file we tried to grab before and
// save the remote image data to it.
Titanium.API.info("Successfully loaded");
file.write(xhr.responseData);
Titanium.API.info(file);
Titanium.API.info(file.getName());
};
};
// Issuing a GET request to the remote URL
xhr.open('GET', url);
// Finally, sending the request out.
xhr.send();
}
}
, 당신은 키의지도와 해당 URL을 저장하는 전역 변수 Ti.App.imageMap
이 필요합니다. 귀하의 필요와 프로젝트에 맞게 코드를 약간 변경해야하지만 좋은 시작점을 제공해야합니다.
어떤 데이터 형식을 사용하고 있습니까? 아들? 웹 서비스에서 얻은 데이터로 무엇을하고 있습니까? – developer82
@ developer82 예 내 데이터 형식은 json입니다. json 객체를 반복하면서 내 목록을 채우고 이미지 뷰의 경로를 설정합니다. – SSS
당신은 로컬 데이터베이스에 데이터를 저장할 수 있습니다. – murli2308