Need a quick help on this (JS)

I mapped the Parameter Observable to get a value but the variable used in storing the value didn’t work in the same JS file. Like this

      var number = this.Parameter.map(function(param){return param.user_number;})

and I tried using variable number in a function in the same JS file like this ;

      function show(){
          var sql = db.query('select * from result where matric_no = ?', number);
          debug_log(JSON.stringify(sql));
          debug_log(matric_no)
      }

but I keep getting [] and Fuse.Scripting.V8.Object

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.

Here is what’s inside

  {"_subscribers":[null],"_isLeaf":false,"_values":["2014235020035"]}

How do I access that number there in?

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.

I have gone through that a quite number of times, my answer is not just there I think.

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!

It’s all explained in Observable docs.

Try changing your Home.js to this:

   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.

Okay. I really appreciate this. Thanks a lot. It has worked, you are a geek.