RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-487790

Алексей Яковлев's questions

Martin Hope
Алексей Яковлев
Asked: 2023-09-24 19:35:35 +0000 UTC

Google 表格 - 执行函数时出错

  • 6

这是函数:

function sumForProduct(code, week) {
  const idMainSheet = "...{some_id}...";
  
  const ss = SpreadsheetApp.openById(idMainSheet);
  const listPrice = ss.getSheetByName("...{some_name}...");
  const data = listPrice.getDataRange().getValues();

  const idxCode = data[0].indexOf("code");
  const idxCount = data[0].indexOf("count");
  const idxPrice = data[0].indexOf("price");
  const idxWeek = data[0].indexOf("week");

  let idxString = -1;

  for (let i = 2; i < data.length; i++) {
    if (data[i][idxWeek] === week && data[i][idxCode] === code) {
      idxString = i;
      break;
    }
  }

  const count = Number(data[idxString][idxCount]);
  const price = Number(data[idxString][idxPrice]);

  return count * price;
}

一切都通过控制台进行;当我想调用表中的公式时:=sumForProduct($D6;E$4),然后出现错误:Exception: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets (строка 4).,如何获得使用 openById 的权限?

google-spreadsheet
  • 1 个回答
  • 106 Views
Martin Hope
Алексей Яковлев
Asked: 2023-05-05 21:27:58 +0000 UTC

如何摆脱更改导入的数组?

  • 7

有一个包含在外部文件中并被导出的数组:

export default [{name: "alex", age: 29}, ...];

在某个类中,我将其导入并放入一个变量的值中:

import persons from "./data.js";

class Persons {
  list = persons;
  ...
}

在该类中,还有几种方法可以使用列表变量并对其进行更改。我有一个为变量设置默认值的方法:

resetToDefault() {
  this.list = persons;
  ...
}

persons但是我发现数组已经在旧数组下发生了变化list,因此list没有更新。如何摆脱改变数组persons?

javascript
  • 1 个回答
  • 26 Views
Martin Hope
Алексей Яковлев
Asked: 2022-12-16 20:13:35 +0000 UTC

状态不更新

  • 6

窗口中有 3 个按钮,通过单击对产品进行排序:

const sortHandler = (name: any, idx: number): void => {
    switch (name) {
            case EProductSort.popular: // популярности
                setProducts(products);
                break;
            case EProductSort.price: // цене
                const sortProductsByPrice = products.sort((a: any, b: any) => {
                    return a.price - b.price;
                });
                setProducts(sortProductsByPrice);
                break;
            case EProductSort.alphabet: // алфавиту
                const sortProductsByAlphabet = products.sort((a: any, b: any) => {
                    if (a.name > b.name) return 1;
                    return 0;
                });
                setProducts(sortProductsByAlphabet);
                break;
            default:
                setProducts(list);
                break;
        }
    };

setProducts并products转移到props:

<Filter setProducts={setProducts} products={products} />

const { list } = useSelector((state: IState) => state.products);
const [products, setProducts] = React.useState<Array<IProduct>>(list);

当我点击按钮时,我到达某个按钮,在case那里我检查了正确排序的数组,但产品的状态没有更新

reactjs
  • 1 个回答
  • 14 Views
Martin Hope
Алексей Яковлев
Asked: 2022-08-08 03:59:12 +0000 UTC

如何找到合适的桌子?

  • 0

所有者表有一个属性:filts VARCHAR(255) ARRAY。轨迹表有一个属性:filt: VARCHAR(255) NOT NULL。

您需要找到这样一个所有者表,以便数组中的至少一个元素filts与来自客户端的元素匹配filt。

我试图做这样的事情:

const queryForFindOwner = `SELECT * FROM owner WHERE filts && ARRAY[$1]`;
const findOwner = await db.query(queryForFindOwner, [track.filt]);

但它没有成功

sql node.js
  • 1 个回答
  • 22 Views
Martin Hope
Алексей Яковлев
Asked: 2022-06-27 02:57:38 +0000 UTC

无法联系服务器

  • 0

我需要检查用户是否已注册。这就是我在文件中所做的_app.tsx:

const MyApp = ({ Component, pageProps }: AppProps) => {
    // code
}

export async function getInitialProps(ctx:NextPageContext) {
    if (!ctx.req) return { props: { } };
    
    const cookie = ctx.req.headers.cookie!;
    const response = await fetch(`${process.env.API_URL}/api/auth/auth`, {
        headers: { cookie }
    })
    const data = await response.json();

    return {
        props: { data }
    }
}

export default MyApp;

我通过中间件在服务器上工作,但它不以任何方式响应(console.log(1)):

const authenticated = (fn: any) => async (req: IGetUserAuthInfoRequest, res: NextApiResponse) => {
    const { method, cookies } = req;

    console.log(1); // не выводится

    if (method === "OPTIONS") {
        return fn(req, res);
    }

    try {
        const token = cookies.token;
        const decoded = verify(token, `${process.env.JWT_KEY}`);

        if (!decoded) {
            return res.status(500).json({
                success: false, message: "Sorry you are not authenticated"
            })
        }

        req.user = decoded;

        return await fn(req, res);
    } catch (e: any) {
        return res.status(500).json({
            success: false, message: "Sorry you are not authenticated: " + e.message
        })
    }
}

export default authenticated;

服务器上的函数本身如下所示:

import authenticated from "../middleware/auth.middleware";

export default authenticated(async function auth(req: IGetUserAuthInfoRequest, res: NextApiResponse) {
    const { method } = req;

    if (method === "GET") {
        try {
            const user: any = req.user;
            const payload = { email: user.email, id: user.id };
            const token = jwt.sign(payload, `${process.env.JWT_KEY}`, { expiresIn: "24h" });

            return res.status(200).json({ success: true, token });
        } catch (e: any) {
            console.log(e);
            res.status(500).json({ success: false, message: `Server error, try again: ${e.message}` });
        }
    } else {
        res.status(405).json({
            message: "We only supported GET"
        });
    }
});

当我登录时,我将所有内容保存在Cookie:

res.setHeader("Set-Cookie", cookie.serialize("token", token, {
    httpOnly: true,
    secure: process.env.NODE_ENV !== "development",
    sameSite: "strict",
    maxAge: 3600,
    path: "/"
}));

简而言之,问题是服务器没有返回任何东西,甚至console.log(1)

node.js
  • 0 个回答
  • 0 Views
Martin Hope
Алексей Яковлев
Asked: 2022-08-08 22:38:29 +0000 UTC

连接 redux 和 nextjs 时出错

  • 0

我这样连接:

import '../styles/styles.sass';
import type { AppProps } from 'next/app';
import { applyMiddleware, createStore } from 'redux';
import allReducers from '../redux/allReducers';
import { Provider, useDispatch } from 'react-redux';
import thunk from 'redux-thunk';
import { composeWithDevTools } from 'redux-devtools-extension';
import React from 'react';
import { useRouter } from 'next/router';
import { auth } from '../actions/userActions';
import { IMessage } from '../interfaces';

const store = createStore(allReducers, composeWithDevTools(applyMiddleware(thunk)));

const MyApp = ({ Component, pageProps }: AppProps) => {
    const router = useRouter();
    const dispatch = useDispatch();
    const [message, setMessage] = React.useState<IMessage>({
        type: "", text: ""
    });
    const [load, setLoad] = React.useState(true);

    React.useEffect(() => {
        dispatch(auth(router, setMessage, setLoad));
        // eslint-disable-next-line
    }, [router]);

    return (
        <Provider store={store}>
            <Component {...pageProps} />
        </Provider>
    )
}

export default MyApp

错误:

Error: could not find react-redux context value; please ensure the component is wrapped in a <Provider>
redux
  • 1 个回答
  • 10 Views
Martin Hope
Алексей Яковлев
Asked: 2022-07-27 19:16:14 +0000 UTC

输出文件时返回 undefined

  • 1

我想访问服务器上的文件并将其输出到客户端,但是req.file = undefined

上传.ts:

import { NextApiRequest, NextApiResponse } from 'next';
import nextConnect from 'next-connect';
import connectMongo from "../../utils/connectMongo";
import multer from 'multer';

connectMongo();

const upload = multer({
    storage: multer.diskStorage({
      destination: (req, file, cb) => cb(null, "../../public/uploads"),
      filename: (req, file, cb) => cb(null, file.originalname),
    })
});

const apiRoute = nextConnect({
    onNoMatch(req:NextApiRequest, res:NextApiResponse) {
        res.status(405).json({ error: `Method '${req.method}' Not Allowed` });
    }
});

apiRoute.post((req:any, res:NextApiResponse) => {
    try {
        upload.single("coverPhoto")(req, {}, err => {
            console.log(req.file); // undefined
        });
    } catch(e) {
        res.status(500).json({ success: false, message: "Ошибка сервера" })
    }
});

export default apiRoute;

export const config = {
    api: {
      bodyParser: true
    }
};

反应处理程序:

const [addProject, setAddProject] = React.useState<IProject>(projectDefaultState);

    const addCoverPhotoHandler = async(event) => {
        if (!event.target.files?.length) return;
        setAddProject({ ...addProject, coverPhoto: event.target.files[0] });
    }

    const addProjectHandler = async(event) => {
        event.preventDefault();

        const response = await fetch(`${process.env.API_URL}/api/upload`, {
            method: "POST",
            body: addProject.coverPhoto
        })
        const data = await response.json();
        console.log(data);
    }

输入:

<MyInput
  accept={[".png", ".svg", ".jpg", ".jpeg"]}
  multiple={false}
  name="coverPhoto"
  placeholder="Обложка"
  type="file"
  onChange={addCoverPhotoHandler}
/>
<MyButton onClick={addProjectHandler}>Опубликовать</MyButton>

node.js
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5