1
我在WinJS中有变量作用域的问题。当变量被改变时,它应该在更大范围内可见,但是在调用函数之后,该变量仅在函数内部具有值。我认为这是readTextAsync的问题,因为当我在没有readTextAsync的函数中填充变量时,它正在工作。WinJS变量只在函数内部变化
这是变量声明:
var fileDate;
这是函数,我调用另一个:
WinJS.UI.Pages.define("index.html", {
ready: function (element, options) {
loadDate();
console.log("główna " + fileDate); //fileDate = undefined
this.fillYearSelect();
},
这是函数,其中变量发生变化:
localFolder.getFileAsync(filename).then(function (file) {
Windows.Storage.FileIO.readTextAsync(file).done(function (fileContent) {
fileDate = fileContent; // example - fileDate=a073z160415
console.log("fileDate " + fileDate);
},
function (error) {
console.log("Reading error");
});
},
function (error) {
console.log("File not found");
});
}
附:对不起我的英语不好。它不完美:)
它还活着!我必须改变我的代码,但是你的解决方案是非常有用的。谢谢。 –