我有一个 Products 组件,它显示一个类别的产品。CategoryId 取自路由参数,然后用户可以对产品进行分页。所以有2个useEffect,一个是categoryId改变的时候,另一个是当前页码改变的时候。如果我使用具有两个依赖项(categoryId 和 currentPage)的一个效果,我找不到将当前页码重置为 1 的方法。(当用户在类别 1 中并转到 2 页时,我想重置页码当类别改变时)
import React from "react";
import {
useProductState,
useProductDispatch
} from "../contexts/product.context";
const Products = props => {
const categoryId = +props.match.params.id;
const { categoryProducts, totalCount } = useProductState();
const [currentPage, setCurrentPage] = React.useState(1);
const dispatch = useProductDispatch();
const pageSize = 2;
const pageCount = Math.ceil(+totalCount / pageSize);
React.useEffect(() => {
setCurrentPage(1);
dispatch({
type: "getPaginatedCategoryProducts",
payload: {
categoryId,
pageSize,
pageNumber: currentPage
}
});
}, [categoryId]);
React.useEffect(() => {
dispatch({ …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 javascript、html、css 创建一个页面,我可以通过在线链接调整图像大小。然而,当调整大小时,我遇到了使用时可能无法导出受污染的画布的错误Canvas.toDataURL()
。我已经在谷歌和这里搜索了这个问题。有人建议将照片的跨域修改为匿名或“*”。我尝试了两种方法,但它对我不起作用。我想知道任何人都可以提供帮助。我的代码在下面的链接中。
https://jsfiddle.net/pangkachun/7axkq9pe/1/
var min_img_width = 60;
var min_img_height = 60;
var max_img_width = 1000;
var max_img_height = 1000;
var resizeableImage = function(image_target) {
// Some variable and settings
var $container,
orig_src = new Image(),
image_target = $(image_target).get(0),
event_state = {},
constrain = false,
min_width = min_img_width, // Change as required
min_height = min_img_height,
max_width = max_img_width, // Change as required
max_height = max_img_height,
resize_canvas = document.createElement('canvas'),
// ----------------- function to int the page ----------------------//
init = …
Run Code Online (Sandbox Code Playgroud)我想创建一个自动生成的ID程序。我可以问一下如何让我的程序具有更高的质量,而我又不需要一一列举吗?
Private ids As List(Of Integer) = New List(Of Integer) From {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
Private count As Integer = 0
Run Code Online (Sandbox Code Playgroud) 我正在构建一个库存管理应用程序,我想创建一个类似于购物车/产品系统的功能。我正处于将产品添加到购物车的阶段,似乎无法找出工作代码。
const mongoose = require("mongoose");
const CartSchema = new mongoose.Schema(
{
active: Bolean,
modifiedOn: Date,
product: [
{
qunantity: String,
name: String,
price: number
}
]
},
{ timestamps: true }
);
module.exports = mongoose.model("Cart", CartSchema);
Run Code Online (Sandbox Code Playgroud)
推车控制器:
exports.postCart = asyncHandler(async (req, res, next) => {
let cart = JSON.parse(req.body.cart);
if (!cart) return res.json(products)
for (var i = 0; i < products.length; i++) {
id = products[i].id.toString();
if (cart.hasOwnProperty(id)) {
products[i].qty = cart[id]
products.push(products[i]);
}
}
return res.json(products);
})
Run Code Online (Sandbox Code Playgroud)
我正在尝试设置一个类似 upsert …
我有以下 mongo DB 架构:
{
"_id" : "5b76c3c037548390fdb5b40e",
"userId" : "4601",
"modified" : ISODate("2018-08-21T19:13:43.301+05:30"),
"rStatus" : "started",
},
{
"_id" : "5b76c3c037548390fdb5b40e",
"userId" : "13",
"modified" : ISODate("2018-08-21T19:13:43.301+05:30"),
"rStatus" : "completed",
},
........
Run Code Online (Sandbox Code Playgroud)
需要通过修改日期和 rStatus 字段的计数来获取数据组,例如
{
modified:"2018-08-21",
count :{"completed":1,"ongoing":4}
},
{
modified:"2018-07-23",
count :{"completed":2,"ongoing":5}
},
Run Code Online (Sandbox Code Playgroud)
我正在使用 $group 但它按修改日期计数,而不是按内部键的值。
mongoose ×2
css ×1
express ×1
html ×1
html5-canvas ×1
javascript ×1
jquery ×1
mongodb ×1
node.js ×1
nosql ×1
react-hooks ×1
reactjs ×1
vb.net ×1