-1

I would like to insert the value here as to send the JSON to backend but unable to get it.

var generateSearchObject = function() {
    var searchObj = {
        "fileName": change, // Here the fileName should be "Change Data"
        "tabType": text.toUpperCase(),
        "offset": offValue,
    };
    return searchObj;
};
var renderCrumbs = function(breadCrumbs, state, node) {
    var change = "Change Data";
}  

Please help!

Ninjakannon
  • 3,751
  • 7
  • 53
  • 76
Ch Sai
  • 9
  • 6

1 Answers1

1

First of all renderCrumbs: function(breadCrumbs, state, node) { ... } makes no sense, because you're using Object property notation with no Object to be found. If it is contained within an Object which is not visible in the code snippet then all is fine, but keep in mind that you must reference the object to call the function in the following code snippet, e.g. obj.renderCrumbs().

Secondly, and problematically, you may be tempted to use change as a global. Don't do this, globals are bad. Read more here. Further information is available elsewhere with a little googling.

The best solution that I can see is to change the functionality of renderCrumbs to

function renderCrumbs(breadCrumbs, state, node) {
    return 'Change Data';
}

and then you can do

var generateSearchObject = function() {
   var searchObj = {
       "fileName": renderCrumbs(), 
       "tabType": text.toUpperCase(),
       "offset": offValue,
   };
   return searchObj;
};
Community
  • 1
  • 1
Jack
  • 804
  • 7
  • 18
  • If you did all that I said then I'll need more code to see where the issue is. – Jack Mar 29 '17 at 20:20
  • As I said, change `renderCrumbs: ...` to `function renderCrumbs() { ... }`, and avoid global variables like the plague. Here's a working version of your code: http://jsfiddle.net/5e2hq95y/7/. You'll be able to see the object logged in the console. – Jack Mar 29 '17 at 20:30
  • Pls do using global just for example – Ch Sai Mar 29 '17 at 20:41
  • `renderCrumbs: function () { ... }` is not valid JavaScript. Why do you want globals? – Jack Mar 29 '17 at 20:42
  • It will never work as long as you use `renderCrumbs: function () { ... }` – Jack Mar 29 '17 at 21:15