employing the result of a function as a string parameter

I need to convert the output of my function into a string variable.

Here's the function I have:

schemaTitle: function() {
    return Categories.findOne({_id: "Gt5prgS4RW3GW23NG"}).title;
}

Now, I want to use the returned value as a string variable in a switch statement like this:

switch(this.schemaTitle) {
    case "HOME":
        return {
            schemaName: "StateSchema"
        };
        break; 
}

Is there a way to accomplish this?

Answer №1

Instead of simply referencing the function schemaTitle, make sure to invoke it. Replace

switch(this.schemaTitle) {

with

switch(this.schemaTitle()) {

This will allow you to use the return value of the function.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

PersistJS callback function is malfunctioning

I stumbled upon a great library for managing client storage. You can find the latest version here: https://github.com/jeremydurham/persist-js However, I encountered an issue with the callback function. var result = store.get('saved_data', func ...

Choose just a single checkbox within the gridview and modify the selected row

I have a GridView with a column containing an ASP CheckBox control. I want the user to be able to check one checkbox and then click on the edit button to edit that particular row. Below is my code for this functionality: <asp:GridView runat="server" C ...

Implementation of Material UI Autocomplete feature with options consisting of an array of objects linking to both ID and label properties

Utilizing the Material UI Autocomplete component in my project has been a key feature. Referencing the official documentation, here are the available options: let options = [ { id: "507f191e810c19729de860ea", label: "London" }, { id: "u07f1u1e810c19 ...

The proper way to link various asynchronous operations enclosed in promises

My current understanding of promises is that they serve as a wrapper for async functions within the outer environment (such as the browser or node.js). However, I am struggling with how to properly connect async operations using promises in software develo ...

In Spring Boot, serializing a Money object to a REST API involves transforming it to contain only the price and

I am working on a project in Spring Boot and MongoDB where I need to serialize the Money result with currency and amount for the API. However, when I use the classic converter, the JSON output for my catalog and product list is not satisfactory. [ { ...

CSRF fails to execute during the initial post submission

This is my first time dealing with CSRF and reaching out to Stack Overflow for the first time. After struggling through the configuration, I finally managed to get it working almost perfectly. However, I ran into an issue where if I open a bookmarked page ...

Is the removal of the Vue-Router link happening when you click on the top app bar icon in Google Material

Review of the following code snippet: <!DOCTYPE html> <html> <head> <title>test</title> <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='vie ...

How to use jQuery to display only the following div with a matching class

I'm encountering an issue while attempting to perform a series of steps using jQuery. Unfortunately, I am unable to achieve the desired outcome. There are 3 steps, each with a class of .wiki-step- followed by a number. Here is my JavaScript code: fu ...

check if JSON value is not null

Display items in ng-repeat only when the value of a certain key is not empty. Here is the code snippet: <a class="item" href="#" ng-repeat="e in events | orderBy:'match_time'" ng-if="e.match_timer !== NaN && e.match_status !== ' ...

Error: NodeJS is unable to access the property 'name' because it is undefined

I've recently delved into the world of NodeJS with the aim of creating a backend API for a car rental agency. I'm puzzled as to why I'm encountering an error even though I have specified 'name' as a string type and ensured that the ...

The reconnection of the Mongoose Connection is not automatically reestablished once the database becomes accessible

In the given scenario, Mongoose tends to lose its connection under specific conditions: The Node App is initiated successfully (DB accessible). The local Mongo server process (version 2.6.10) is stopped and then restarted after a gap of 15 seconds (DB re ...

Modifying the CSS class of an element does not produce the desired effect after altering its styles using JavaScript

html: <input id="myinput" class="cinput" type="image" src="http://www.foodwater.org.au/images/triple-spiral-3-small-button.jpg"/> <br><br><br><br> <button id="s">set to visible class</button> <button id="h"> ...

When the mouse hovers over a specific area, a sIFR element

Here is the html code that I am working with: <li><a href="#"><span class="font Berthold-light">1</span>Consectetur adipiscing elit risus.</a></li> I have successfully replaced the number within the span using sIFR. Ho ...

Utilizing an external script by importing it with a script tag and integrating its functions into a React component

I am currently using the teller.io API in my application. To initiate authentication within my react app, I need to import a script from them since there is no react library available. Once the script is added to the DOM, I need to use a function from it. ...

Establishing default parameters for angular pipes

Is there a way to establish default settings for an angular pipe without creating a custom one myself? I frequently utilize the currency pipe in this manner {{ price | currency:'EUR':'symbol':'0.2-2':'de' }} I&apo ...

Is there a way for me to figure out if a Primefaces RadioCheckbox has been selected?

Despite the numerous examples available on how to count checked checkboxes, I am facing difficulties in getting it to work. My goal is to enable a button when at least one checkbox is checked on the page, and disable it when none are selected. However, n ...

Issue encountered while generating a package using npm init in Node.js

I am currently in the learning process of NodeJs from tutorialspoint(TP). Following instructions provided in this link, I tried to create a package by running the following command: C:\Program Files (x86)\nodejs>npm init This utility will w ...

Guide on developing a dynamic Navbar component on Laravel Mix with Vue Js

As I delve into learning and practicing Vue.js, my goal is to create a component that includes elements like Navbar and Footer within a single view. Initially, I set up an index for the first view but faced an issue with adding the navbar as it did not sho ...

What is causing the TypeError in Discord.js when trying to read the 'voice' property? Any help troubleshooting this issue would be greatly appreciated

Hey everyone, I'm having an issue with my play.js file that I obtained from a Source Bin. If anyone could provide some assistance, it would be greatly appreciated. const ytdl = require("ytdl-core"); const ytSearch = require("yt-search"); //Global que ...

What is the predefined value for a multi-select generated by the ng-for directive in Angular?

I am having trouble setting default selected values for the multi-select. Despite trying various methods such as initializing the ngModel to bind the variable and using [selected] = "selectedSegment == 'S1'", none of them seem to be effective fo ...