嗨,我是jquery/javascript的新手。我創建了一個全局變量。我將這個變量的值設置爲這樣的函數內部值:如何在JQuery中設置全局變量/ javascript
var arr;
CreatecheckPassword: function() {
var pas = document.getElementById("pos-password")
var user = new db.web.Model("res.users").get_func("read")(this.session.uid, ['password']).pipe(function(result) {
arr = result.password;
alert(arr);//prints the expected value
});
alert(arr);//prints nothing
},
我不知道我在哪裏做錯了。我努力嘗試,但無法找到解決方案。有人可以幫忙嗎?
你有一對夫婦的語法錯誤... – elclanrs 2012-03-10 09:13:23
我猜想,你的數據庫訪問功能是異步的,這意味着控制繼續時執行的回調之前打印任何警告和'arr'變量已設置。 – nnnnnn 2012-03-10 09:16:40
那我該如何設置這個變量的值。不能沒有數據庫操作。 – Inventillect 2012-03-10 09:21:49