Vue JS lodash findKey nested object with dot notation returns undefined

I’m trying to pull out a value for a nested object key from some eligibility array that I’ve got, but I’m getting an undefined value for some reason and need to know what I’m missing.

Given the following array:

const eligibilityCriteria = [
  { field: 'loan.amount', operator: '>=', value: 1000 },
  { field: 'loan.term', operator: '>=', value: 1 },
  { field: 'applicant.birthday', operator: '>=', value: 40 },
  { field: 'applicant.isHomeowner', operator: '==', value: false }
]

I need to find loan.amount from a nested object and pull out it’s value:

My big nested object is (coming from the store)

application: {
  meta: {
    brand: '',
    version: '',
    affiliate: '',
    affiliate_full: '',
    campaign: '',
    client_hostname: '',
    client_href: '',
    client_origin: '',
    client_useragent: '',
    client_ip: '127.0.0.1',
    icicle_hash: ''
  },
  loan: {
    amount: 500,
    term: null,
    purpose: null
  }
}

My function right now is:

checkEligibility () {
  const eligibilityCriteria = [
    { field: 'loan.amount', operator: '>=', value: 1000 },
    { field: 'loan.term', operator: '>=', value: 1 },
    { field: 'applicant.birthday', operator: '>=', value: 40 },
    { field: 'applicant.isHomeowner', operator: '==', value: false }
  ]

  for (const [index, offer] of this.datasets.offers.entries()) {
    const eligibility = eligibilityCriteria

    if (eligibility) {
      for (const [ci, criteria] of eligibility.entries()) {

        // TODO: this fails to pull the value, returns undefined
        const field = _.findKey(this.$store.state.application.application, criteria.field)
      }
    }
  }
}

What am I missing?

Use variable in ejs script tag

I want to use variable (or variables) in ejs file in the script tag ,I also want to pass the rendered file to a function for taking screenshot from ejs file.

But now I have 2 problems :

1.I don’t know how to pass the variable in server file to the ejs file and render and use it without app.get… (in express) because it’s server side and I want to use html file.

2.I don’t know how to use variable in ejs file in the script tag

these are my files :

index.ejs


<div id="tvchart"><% symbol %></div>

<script>
//some codes 
 var symbolD =<%= symbol %>;
fetch(`http://127.0.0.1:9665/fetchAPI?endpoint=https://api.binance.com/api/v3/klines?symbol=${symbolD}&interval=1m&limit=1000`)
</script>

server.js

// set the view engine to ejs
app.set("view engine", "ejs");
const symbol = "EGLDUSDT"

const file = ejs.render("./index.ejs" , symbol);
console.log(file)

So Why my ejs and server file doesn’t work?

Passing numeric data containing django to javascript

am having a problem with char inside numeric data, it’s too large to be cleaned. anyways.
I want to replace < and > from value.
just posting relevant codes.
views.py

def search_result(request):
    if request.method == "POST":
        ChemSearched = request.POST.get('ChemSearched')
        tarname = BINDLL.objects.filter(targetnameassignedbycuratorordatasource__contains=ChemSearched).exclude(ki_nm__isnull=True)[:120]
        
        return render(request, 'Search/search_result.html',{'ChemSearched':ChemSearched,'tarname':tarname})

Html side

<script>
     data=[{% for Bindll in tarname %} {
                group: '{{ Bindll.targetnameassignedbycuratorordatasource }}',
                     variable:'{{ Bindll.zincidofligand}}',
                     value: {{Bindll.ki_nm|safe}}
                    }, {% endfor %}];

which is used by graph d3.js.
all go well unless I have ‘<‘ or ‘>’ in value I’ll have this result

Uncaught SyntaxError: Unexpected token ‘>’
or if use escape value: {{Bindll.ki_nm|escape}}
Uncaught SyntaxError: Unexpected token ‘&lt’
any function to be used in Html side javascript to replace char or anything and keep only numeric like regex replace.
thanks.

firebase initialize with vuejs 2022

i wish to initialize my vuejs project with firebase.

But because of the new update i can’t.

i must use import { initializeApp } from "firebase/app"; AND const app = initializeApp(firebaseConfig);

but i have 2 problems with this:

1)

This dependency was not found: To install it, you can run: npm install –save firebase

it didn’t found my module. In my package.json it’s present.

2)

to initialize my instance vuejs i need to write :

new Vue({ router,render: h => h(App)}).$mount('#app')

but i have “app” from firebase missing.

thanks for your help 🙂

react native local push notifications IOS – (react-native-push-notification)

I’m using the (react-native-push-notification) package for my alarm ios app but there is an issue when the app is in the background notification banner appears for a short time but does not receive any callback in the background because I need a callback, where I ring a sound continuously.
When the app is in the background notification banner appears with sound only for 6 seconds but I need to play a sound continuously when a notification appears in the background.

How do I understand my addEventListener error code? [duplicate]

I’m attempting to build a simple ‘To-Do List’. I’m trying to add a new P element to my existing div. Does anyone have any ideas regarding the following error code?

Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')

I feel like my HTML button (submitButton) click isn’t being received, although I could be wrong.

var toDoList = document.getElementById("toDoList"); // div with p elements within
var submitButton = document.getElementById("submitButton"); // HTML button
var textInput = document.getElementById("textInput"); // HTML text input

function addFunction(){
    var newItem = toDoList.createElement("p");
    newItem.innerText = textInput.value;
    document.toDoList.appendChild(newItem);
}

submitButton.addEventListener('click', addFunction);

Show an element only if the data given by the Api exists

I’m using Pokeapi and want to display the types of the pokemon in 2 different element bc I’m applying a style (the background color) according to the type of the pokemon. The problem is that it shows the first 3 pokemon but not the fouth bc it has only one type and it can’t find the second type (which doesn’t exist) in the data given by the api.

Here’s my JS :

function displayPokemon (pokemon) {
    const pokemonEl = document.createElement('li');
    const name = pokemon.name;
    const type1 = pokemon.types[0].type.name;
    const type2 = pokemon.types[1].type.name;
    const pokemonHTMLString =
        `
        <div class="pokemon_container ${type1} ${type2}">
            <div class="pokemon_container_image">
                <img class="pokemon_container_image_sprite" src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${pokemon.id}.png" loading="lazy" alt="${name}"/>
                <img class="pokemon_container_image_shiny" src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/shiny/${pokemon.id}.png" loading="lazy" alt="${name}"/>
            </div>
            <h3 class="pokemon_number">#${pokemon.id.toString().padStart(3, '0')}</h3>
            <h2 class="pokemon_name" onClick = "selectPokemon(${pokemon.id})">${name}</h2>
            <a class="pokemon_type" id="${type1}">
                <img id="${type1}" alt="${type1}"></img>
                <span>${type1}</span>
            </a>
            <a class="pokemon_type" id="${type2}">
                <img id="${type2}" alt="${type2}"></img>
                <span>${type2}</span>
            </a>
        </div>
    `
    pokemonEl.innerHTML = pokemonHTMLString;
    pokedex.appendChild(pokemonEl);
};

Here’s the error : “Uncaught (in promise) TypeError: pokemon.types[1] is undefined”

Before that I was mapping the types and showing them in one element but I want to do 2 separate elements and I don’t know if my code is wrong and I have to modify something or if I have to create a function or an if else statement.

Redux State changes but component not rerendering

My issue is that my redux state is updating (I can see it in the redux dev tool) but my component is not updating, it’s not putting the last value of my array initialState.userWeight
Here is what my reducer looks like :

case 'NEWWEIGHT':
           const weight = action.payload.weight
           const date = action.payload.date
           state.userWeight = [...state.userWeight, {weight: weight, date: date}]
           return {...state}

Here is my initialState :

const initialState = {
    userName: '',
    userSize: 0,
    userWeight: [],
    userDate: '',
}

Here is what my component looks like :

    const userWeightRedux = useSelector(state => state.userInfo.userWeight[Array.length - 1].weight)

    console.log(userWeightRedux)

...
<Text style={styles.user}>{userWeightRedux}</Text>

So console.log(userWeightRedux) dosen’t change.
I am new to react, redux and don’t fully understand the spread syntax, maybe the problem is here but did’nt find anything, hope you can help me :).

Can I use regex within toHaveClass?

I have an element with a long class that contains a dynamic suffix to denote the type of icon that should be displayed, think of some-very-long-classname-for-an-icon-{iconType}, where {iconType} is likely to be filled with a string like success or error etc.

In React Testing Library, I am wanting to assert that I have a particular icon class applied, however I don’t want to clutter up my tests by having the full prefix some-very-long-classname-for-an- at each part.

Rather than store this prefix as a variable I was wondering if it would be possible to use regex to specify? Something along the lines of /icon-success$/.

I was thinking of using toHaveClass as I know this will work when specifying the full class name for the test:

expect(myComp).toHaveClass('some-very-long-classname-for-an-icon-success');

however, upon my travels I have found that toHaveClass doesn’t take Regex 🙁

I did think of doing something along the lines of

expect(myComp).toHaveClass(expect.stringContaining('icon-success'));
expect(myComp).toHaveClass(expect.stringMatching(/icon-success$/));

however these also didn’t seem to work…

Image in NextJS does not allow template literals inside src when deploying on vercel

I have a userdropdown menu that I want to show the picture of the client that authenticated. I use nextAuth to authenticate. I can see the picture of the user and name of the user turns well with useSession().

enter image description here

I show the picture of the user in localhost without problem. Here how I show it with Image tag.

  <li className="py-1 px-3 hover:underline leading-8 flex">
              <Image
                width={40}
                height={40}
                className="mr-3"
                src={status === "authenticated" ? session.user.image : profile}
                alt="img"
              />
              <span className="ml-3">User</span>
            </li>

But when I sent it for production to vercel, it throw error and does no work like in localhost.
Here the error

enter image description here

JQuery function – Run it automatically once a day instead of a on click action

I am new to JavaScript and JQuery.

We have a WordPress theme serving as an online directory. This theme uses a JSON file to display our listings on our map. For each of our modifications on a listings we must click on a button named “JSON Generator” to update the data of the map. The problem is that we are currently adding / modifying a lot of content on our map so it requires a lot of manual regenerations.

Screenshot of the button and his html declaration

Is there a way to replace the ON CLICK launch of the JavaScript function regenerating the JSON by an automatic launch every 24 hours for example?

Here is the start of my actual .js file :

;( function( $ ){



// Json Generator

var directoryManagerAdmin = function () {

    this.param = lava_dir_admin_param;

    this.init();

}



directoryManagerAdmin.prototype.constructor = directoryManagerAdmin;

directoryManagerAdmin.prototype.init = function() {

    var self = this;

    $( document )

        .on( 'click', '.lava-data-refresh-trigger', this.onGenerator() )

        .on( 'click', '.fileupload', this.image_upload() )

        .on( 'click', '.fileuploadcancel', this.image_remove() )



    $('button[data-listing-type-generator]').each(function(){

        var listingType = $(this).data('listing-type-generator') || false;

        var Instance = self.onGenerator(listingType);

        $(this).on('click', Instance);

    });

    self.bindJsonEditor();

}

directoryManagerAdmin.prototype.onGenerator = function(type) { THEN YOU HAVE THE VERY LONG FUNCTION....

I think that I have to replace the launcher : .on( 'click', '.lava-data-refresh-trigger', this.onGenerator() ) by an automatic launcher every 24 hours or so.

I found out how to get the current date : var date = new Date().toLocaleDateString();, I also know that I may have to use the setInterval action but I don’t know how to use it 🙁

Thanks by advance if you have any clue to help me !

JS append not working when using a for loop

I have this code:

success: function (result) {
   var textoTipos = $('.cargarTextosTipo');
                      
   for (var selecttipos of textoTipos) {
       selecttipos.append(`<option value="0">Hello this is a test</option>`);

   // some code

   }

}

My problem is that inside loop selecttipos.append(`<option value="0">Hello this is a test</option>`); is not working and it is not appending to a select component but this way worked but this is not the way I am looking for:

 success: function (result) {
    var textoTipos = $('.cargarTextosTipo');
   textoTipos.append(`<option value="0" > Hello this is a test </option>`);

}

How do I make it work using a loop? this is the way I want because I have to go through each select node and do some stuff later rather than applying to all select stuff.

How can I pull the Tinymce editor to the update modal in the format I want?

How can I get the formatted version of the update modal? I get an error:

tinymce.js:13767 Uncaught TypeError: Cannot create property ‘format’ on string ‘<h2 style=”box-sizing: border-box;

var secilendeger;

function textDuzenle(pid) {
  update = true;
  $('#exampleModalSizeLg').modal('show');
  secilendeger = $('#kt_datatable').DataTable().data().filter(x => x.Id == pid)[0];
  //$('#p_Ack').val(secilendeger.Desc);
  tinymce.get("p_Ack").getContent(secilendeger.Desc);
}