If you’re calling the show() function before the derived number Observable is populated, you might not be getting any value there. It’s populated asynchronously.
As for the Fuse.Scripting.V8.Object, you can do this: console.log(JSON.stringify(matric_no)) to see what’s inside complex structures.
Since you’re asking about an Observable, why don’t you first go and give Observable docs a thorough read?
You really need to start posting complete, minimal reproductions. There is no good way for anyone to answer “how do I access X” without seeing what you do to “X” and where it comes from.
Disclaimer: a complete, minimal reproductions == single-UX-file app that one can copy-paste and run.
Here is where the data is coming from (SplashPage.js)
var Observable = require('FuseJS/Observable');
var matric_no = Observable('');
var password = Observable('');
function Login(arg){
var r = '';
var std_matric = arg.data.matric_no.value;
var std_pass = arg.data.password.value;
if(std_pass == '' || std_matric == ''){
debug_log('Enter matric/password');
//error_empty.value = true;
}
r = db.query('select * from student where matric_no = ? and user_password = ?',std_matric,std_pass);
if(r != ''){
router.goto('home',r[0]);
}else{
debug_log('Incorrect Login Details');
//error_flag.value = true;
}
}
module.exports = {
Login:Login,
matric_no:matric_no,
password:password
}
Here is the Home.js
var student = this.Parameter;
var sqlite = require('SQLite');
var db = sqlite.openFromBundle('db.sqlite');
var matric_no = this.Parameter.map(function(param){return param.matric_no});
function show_result(args){
var name = args.data.name;
var semester = args.data.value;
var sql = db.query('select * from result where matric_no = ?',matric_no);
debug_log(JSON.stringify(matric_no));
debug_log(matric_no);
}
module.exports = {
matric_no:matric_no,
show_result:show_result
}
Here is the full code, the value of the matric_no variable is not accessible in the show_result() function.
That is not a complete, minimal reproduction - I can not copy&paste and run it. The keyword is “complete” in this case.
Let me repeat myself: If you’re calling the show_result() function before the derived matric_no Observable is populated, you might not be getting any value there. It’s populated asynchronously.
And again: Since you’re asking about an Observable, why don’t you first go and give Observable docs a thorough read?
I have updated the code, please try look into it. I just need to access the matric_no variable in other functions after the Observable(this.Parameter) mapping.
That is still not a complete, minimal reproduction. Your sqlite query might be failing, you might be calling show_result() function before the derived Observable is populated etc. There is no way to help you with the bits of code you’re showing.
There is nothing I can paste any longer, you helped me with that sqlite query some days ago and they routing and also working fine, the only problem is that I can not access the values of the variables I retrieved from the Parameter in the same JS file.
I need this variable (matric_no) of the code:
var matric_no = this.Parameter.map(function(param){return param.matric_no});
to be accessible in the same file but it’s returning a Fuse.V8.Scripting.object instead of the number ‘2014235020035’ as seen in the debug_log(JSON_stringify(matric_no))
It is an Observable, so it is perfectly fine that it’s Fuse.Scripting.V8.Object.
Derived Observables are populated asynchronously, as I explained a couple posts ago. Plus, they are only calculated if they are consumed, that is - they have at least one subscriber. Since you have added matric_no to your module.exports, it suggests that there, indeed, is a subscription to it. However, I don’t see that because you’re not showing how you use it in UX!
var student = this.Parameter;
var sqlite = require('SQLite');
var db = sqlite.openFromBundle('db.sqlite');
var matric_no = this.Parameter.map(function(param){return param.matric_no});
matric_no.subscribe(module);
function show_result(args){
var name = args.data.name;
var semester = args.data.value;
var sql = db.query('select * from result where matric_no = ?',matric_no.value);
debug_log(matric_no.value);
}
module.exports = {
matric_no:matric_no,
show_result:show_result
}
So once again: there is absolutely no way to help you if you’re not sharing COMPLETE reproductions. And “there is nothing I can paste any longer” is just a false statement. Yes, you can. You need to prepare a minimal repro that includes both UX and JS code, and holds that in a single-UX-file app.