FabricJS object functions dont work after loadFromJSON

I’m saving my canvas in JSON, and storing it in firestore.

jsonResponse.fabricInfos = this.canvas.toDatalessJSON([some properties]);

I already tried with toJSON too

The save works, and on load it loads everything right on the screen, but all the functions I try to use on the objects give an error.

Exemple:

object.set({opacity: 1});

I will always receive: set is not a function…

VueJS use v-for after mounted or else method

i need to get array after mounted was done, for create child of section in html.
Like – getting objects from api -> return array with objects -> create child blocks.

first time i used like

mounted() {
apiLoop.then((result) => {
    let tracksArray = result.data
      for (let i = 0; i < tracksArray.length; i++) {
        let genSection = document.querySelector('.charts')
        genSection.appendTo(`<div class="container card chartsCard" data-musicid="${tracksArray[i].id}">)
      }
})}

But how to make it right? Use v-for (but how to send tracksArray to v-for?) or create element in mounted?

How can i access data from a Typescript object?

I am using the CronJob API to schedule Cron Jobs using google cloud functions. This is the code for creating the job.

 var options = {
'method': 'PUT',
'url': 'https://api.cron-job.org/jobs',
'headers': {
  'Content-Type': 'application/json',
  'Authorization': `Bearer ${BEARERID}`
},
body: JSON.stringify({
  "job": {
    "url": url,
    "enabled": true,
    "saveResponses": true,
    "schedule": {
      "timezone": defaultTimezone,
      "hours": [
        hour
      ],
      "mdays": [
        day
      ],
      "minutes": [
        minute
      ],
      "months": [
        month
      ],
      "wdays": [
        -1
      ]
    }
  }
})
 };

request(options, function (error: any, response: any) {
    var jobID = response.body[`jobId`];

    console.log(`job id is ${jobID}`);
    console.log(`this is the body ${response.body}`);
  });

This request returns a map in the body which contains the cron Job ID and it’s in the format

{"jobId":3978075}

I need to access the Job ID, but nothing i try is working. Nothing at all, and i am super frustrated.

THINGS IVE TRIED

var jobID = Object(response.body)["jobID"]
var jobID = response.body["jobID"]
var jobID = response.body.jobID

Nothing works. Please help.

The DOM is loading but is not displayed without clicking on screen mobile Vue.js

I have a very strange problem that I really don’t know how to solve.
When I’m on my mobile, my page loads as follows homepage

But when you click on the screen all the components appear.
Can I generate a fake click on my mobile or something?
I really have no idea what’s going on
I would also check how the scripts load, I have nothing to do with async defer
Do you think that a fake click would solve me?

For example, when it loads its page to click / touch on the mobile?

How to enable eslint caching?

I’m trying to enable eslint caching, following this part of the user guide

My command is npm run lint -- --cache=true, and the lint script just runs a script that spawns esw (which itself just runs eslint — we have v7.x installed) as a child process.

From earlier in the user guide

Caching:
  --cache                         Only check changed files - default: false
  --cache-file path::String       Path to the cache file. Deprecated: use --cache-location - default: .eslintcache
  --cache-location path::String   Path to the cache file or directory
  --cache-strategy String         Strategy to use for detecting changed files in the cache - either: metadata or content - default: metadata

But when I run the command I get:

npm WARN invalid config cache=true
npm WARN invalid config Must be a valid filesystem path

Even supplying a --cache-location=.eslintcache doesn’t change the error message.

How am I supposed to enable caching?

Data in array got overwritten while using .push()

I am working on the undirected graph. I don’t understand why does it overwrites the data in Array when I’m using .push() . I can get these normal while console.log the variable besides pushing the data of it to an Array. Below is the code. At printAllPathsUtils function.

let v;
let nearList;
let result = [];

function Graph(vertics) {
    v = vertics;

    initAdjList();
}

function initAdjList() {
    adjList = new Array(v);

    for (var i = 0; i < v; i++) {
        adjList[i] = [];
    }
}

function addNode(s, d) {
    adjList[s].push(d);
}

function printPaths(s, d) {
    let isVisited = new Array(v);
    for (var i = 0; i < v; i++) {
        isVisited[i] = false;
    }

    let pathList = [];

    pathList.push(s);

    printPathsUtil(s, d, isVisited, pathList);
}

function printPathsUtil(u, d, isVisited, pathListLocal) {

    if (u == d) {
        result.push(pathListLocal);
        console.log(result)
        return;
    }

    isVisited[u] = true;

    for (var i = 0; i < adjList[u].length; i++) {
        if (!isVisited[adjList[u][i]]) {
            pathListLocal.push(adjList[u][i]);
            printPathsUtil(adjList[u][i], d, isVisited, pathListLocal);
            pathListLocal.splice(pathListLocal.indexOf(adjList[u][i]), 1);
        }
    }

    isVisited[u] = false;
}

Graph(6);

addNode(0, 3);
addNode(0, 5);
addNode(1, 4);
addNode(1, 5);
addNode(2, 3);
addNode(2, 4);
addNode(3, 2);
addNode(3, 0);
addNode(3, 4);
addNode(3, 5);
addNode(4, 1);
addNode(4, 2);
addNode(4, 3);
addNode(4, 5);
addNode(5, 0);
addNode(5, 1);
addNode(5, 3);
addNode(5, 4);

var s = 0;
var d = 5;

printPaths(s, d)

In if(u == d), there is where the problem occur. While using console log, I can get what I expect, but using result.push(pathListLocal), it’s giving me back a weird result. You can see the screenshot from the terminal below. That’s what I have got while using result.push(pathListLocal) and console.log(result) at the same time.
enter image description here

When using console.log(pathListLocal) alone, this is what I got:

enter image description here

What I want to do is put the result from pathListLocal into the Array result. Anyone have clue on how is this happening?

Edit: In more straight way, I would like to have [[ 0, 3, 2, 4, 1, 5 ],[ 0, 3, 2, 4, 5 ], [ 0, 3, 4, 1, 5 ], [ 0, 3, 4, 5 ], [ 0, 3, 5 ], [ 0, 5 ]] from the variable result

Is there any way I can click on “OK” in the js confirm dialog box programatically?

I have written this jQuery function to achieve some automation in a website. Now, when “.btn-danger” is clicked a confirm dialog box opens up with two options “OK” and “Cancel”. I want to click on “OK” programmatically (maybe using js) as this will be a repetitive process.

$(".toolbar li:nth-child(2)").click(function(event) {
    setTimeout(function () {
     $("a.btn-danger").trigger("click");
    }, 1000);   
});

Fastify ejs mongodb don’t display the page with data

I am creating a website and I am currently making a database system with mongodb, which I have almost finished but, since I updated a fastify package, the page only displays of white

My package:
fastify: 4.0.3
path: 0.12.7
@fastify/view: 7.0.0
mongodb: 4.7.0
dotenv: 16.0.1
ejs: 3.1.8
@fastify/static: 6.4.0
@fastify/formbody: 7.0.1
fastify-plugin: 3.0.1
mongoose: 6.4.0

My route code:

fastify.get("/result", async function (request, reply) {
 let search = request.query.search;
  
  if (search) {
    await dbAnime.find({ aliases: search })
      .toArray(async function (err, have) {
      if (!err) {
          if (have.length > 0) {
             reply.view("/pages/result.ejs", { results: have }).then(() => {
                console.log("replied")
             });
         console.log(have);
          client.close;    
          } else {
              reply.view("/pages/result.ejs", { results: have });
          }
        } else {
          reply.code(400)
          console.error(err);
        }
      });
  };
});

i don’t have any error in console, then i don’t know how to fix it

how to store the value of a key for a object and pass it to the function which is a value of another key in the same object

"sideCardInfo": {
                        "title": "Hospital Admission",
                        "reportTitle": "Hospital Admission Report",
                        "subTitle": "Per 1000 Members",
                        "dateFilter": [
                            {
                                "date": previousYearRange,
                                "value": calculateAverage(allInsightData.map(obj => Number(obj.hospital_admissions_cnt_py))),
                            },
                            {
                                "date": currentYearRange,
                                "value": calculateAverage(allInsightData.map(obj => Number(obj.hospital_admissions_cnt))),
                            }
                        ],
                        "percentage": calculatePercentage( calculateAverage(allInsightData.map(obj => Number(obj.hospital_admissions_cnt_py))), calculateAverage(allInsightData.map(obj => Number(obj.hospital_admissions_cnt)))),
                        "tooltipText": ""
                    },

In the above object inside dateFilter for value i am using a calculateAverage function to get the value i need to pass the same value as parameter for calculatePercentage which is a value for percentage key in the same object how to store the calculateAverage at dateFilter and pass it to calculatePercentage so that i can avoid calculating average two times

Javascript returning SUM 0

Sorry for this basic JS question.

I have this code:

let myResult = 0

        if (value0 > (value1 * value2)) {
          myResult = (value1 * value2) * value3;
        } else {
          myResult = valueExtra * value3;
        }
        return ( myResult )

my value is always 0.

I know it’s because let is not changing, but I don’t know why.

Could you help me, please?

Datatables checkboxes start with some checkboxes checked

Can someone help me setup the Checkboxes extension for Datatables to start with some some checkboxes checked? The documentation on this matter can be found here, and although I’ve done everything that’s required, it still fails to do what’s supposed to do.

Basically I’m passing an array of the IDs that I want to be checked upon pageload, and I’m checking the ID of each row to check if it’s contained in the array, but still all rows start unchecked.

jQuery(function($) {

  $('#questions-pool').DataTable({
    ordering: false,
    dom: '<"#upper-controls"lf>t<"#lower-controls"ip>',
    lengthMenu: [
      [10, 50, 100, -1],
      [10, 50, 100, 'All']
    ],
    initComplete: function(settings) {
      var api = this.api();
      var selected = [387, 386, 385, 384, 383, 382, 381, 380, 379, 378];
      alert(selected);

      api.cells(
        api.rows(function(idx, data, node) {
          alert(data[2]);
          return (selected.indexOf(data[2]) >= 0) ? true : false;
        }).indexes(),
        0
      ).checkboxes.select();
    },
    columnDefs: [{
      targets: 2,
      checkboxes: {
        selectAllPages: false,
      }
    }],
  });

});

You can find a working fiddle here. Everything is working fine, except for the desired rows selection at startup.

Any help will be greatly appreciated. I’m struggling with this for 2 days already…

Axios Network Error depending on CORS policy in Node JS

While trying to carry out put axios request the following error occurs:

enter image description here

The CORS module was installed and switched in server.js file, but seems that doesn’t work.
By the way there are no any CORS headers in the request:

enter image description here

So in server.js file the CORS module is implemented. I tried to add {origin: “http://localhost:3000”} in brackets but that didn’t work. The brackets are empty.

server.js:

const express = require("express");
const mongoose = require("mongoose");
const apiRoutes = require('./routes/apiRoutes');
const path = require('path');
const cors = require("cors")
require("dotenv").config();

const app = express();
const PORT = 3001;
app.use(cors());
app.use(express.static(path.join(__dirname, 'images')));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(apiRoutes);

mongoose
    .connect(process.env.MONGO_URL)
    .then(res => console.log("The connection to the Database was carried out successfully."))
    .catch(error => console.log(`The Error while connecting to the Database occured: ${error.message}`))
    
app.listen(PORT, 'localhost', error =>
    console.log(error ? `The Error occured: ${error.message}.` : `The Listening Port is ${PORT}`)
);

the route:

router.put("/api/newAd/:creationDate", (req, res) => {
  console.log(req.body);
  // Ad.updateOne({ creationDate: req.body.creationDate }, {
  //   textInfo: req.body
  // })
})

the client side:

    const saveAndPlace = () => {
        axios.put(`/api/newAd/${creationDate}`)
        .catch(err => console.log("error", err))
    };

So why these errors occur? And why the headers are not shown in the network panel?

Merge Objects under the same ID and display in HTML Table

I am actually stuck on something. As the title above tells you. I need helps on how to get the result for this.

Below is the code

let Array = [{
  reference: "A0002",
  sendTo: "USA",
  item: "sticker",
  sku: 0921380,
  quantity: 1
},
{
  reference: "A0002",
  sendTo: "USA",
  item: "toy",
  sku: 0921381,
  quantity: 2
}, {
  reference: "A0002",
  item: "pencil",
  sku: 0921382,
  quantity: 2
},
 {
  reference: "A0003",
  item: "sticker",
  sendTo: "USA",
  sku: 0921380,
  quantity: 2
}]

console.log(Array)

Result I would want when HTML is applied is:

reference: A0002
sendTo: USA
item: sticker, toy, pencil
sku: 0921380, 0921381, 0921382
quantity: 1, 2 ,2

reference: A0003
item: sticker
sendTo: USA
sku: 0921380
quantity: 2

However, I need to make it appear inside a HTML Table