开发者

Over writing a boolean value in JavaScript

开发者 https://www.devze.com 2023-02-22 22:32 出处:网络
var PageLoad = true; I have a file named properties.js which holds this value and i need to change this value into false when a button is clicked. The button is in another JS file.
var PageLoad = true;

I have a file named properties.js which holds this value and i need to change this value into false when a button is clicked. The button is in another JS file.

How can i do it?

var appDir = Titanium.Filesystem.getApplicationDataDirectory();
var p开发者_C百科ropertiesFile = Titanium.Filesystem.getFile(appDir, 'properties.js');
propertiesFile.write("These is the contents");

What should i write??


I would recommend using the Properties methods that are provided by Titanium to solve this problem instead of reading and writing files yourself

http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.App.Properties-module

http://wiki.appcelerator.org/display/guides/Working+with+Local+Data#WorkingwithLocalData-ApplicationProperties


If properties.js holds just that single line, then you could use the following to write JavaScript that sets the value to false in a click handler for the button you mentioned:

var appDir = Titanium.Filesystem.getApplicationDataDirectory();
var propertiesFile = Titanium.Filesystem.getFile(appDir, 'properties.js');
propertiesFile.write("var PageLoad = false;");

But unless I misunderstand Titanium (new to me) this won't set that variable in the context that your JavaScript is executing. Maybe we can help you more if you give some background into what the properties.js file is used for and by - does something else read that file and execute the contents?

0

精彩评论

暂无评论...
验证码 换一张
取 消