正在使用react,然后遇到了这样的问题
Uncaught URIError: This is likely caused by an invalid percent-encoding
Run Code Online (Sandbox Code Playgroud)
我目前正在使用新闻 API,一些文章可能包括%. 我的整个应用程序依赖于在网址中显示新闻文章名称,因为我使用this.props.match.params.id
我尝试在网上寻找解决方案,但大多数人都不清楚如何解决这个确切的问题。
有一个简单的解决方法吗?
但是,我能够成功地找到对象中的最大值.存在问题,即无法显示具有该值的关联键.
var obj = {
t1: 1,
t2: 33,
t3: 10,
t4: 9,
t5: 45,
t6: 101
//...
}
// create an array
var arr = [];
// loop through the object and add values to the array
for (var p in obj) {
arr.push(obj[p]);
}
// sort the array, largest numbers to lowest
arr.sort(function(a,b){return b - a});
// grab the first 10 numbers
var firstThree = arr.slice(0, 3);
console.log(firstThree);Run Code Online (Sandbox Code Playgroud)
它可以显示最高值,但是我很难用它显示键.
结果应该是这样的
var result = {
t6: 101,
t5: 45, …Run Code Online (Sandbox Code Playgroud) 尝试在论坛上搜索,但找不到任何与我需要的内容完全相同的内容。我基本上试图#从收到的结果中删除符号,这是正则表达式的虚拟示例。
let postText = 'this is a #test of #hashtags';
var regexp = new RegExp('#([^\\s])', 'g');
postText = postText.replace(regexp, '');
console.log(postText);Run Code Online (Sandbox Code Playgroud)
它给出以下结果
this is a est of ashtags
Run Code Online (Sandbox Code Playgroud)
我需要更改什么才能仅删除主题标签而不删除每个单词的第一个字母
尝试设置 websocket 连接,当我在本地主机环境中时它工作正常,但是一旦我设置了 docker 环境,客户端(react)就很难与 express 建立 web-socket 通信。我应该定义什么 url 以在 2 之间打开 web-socket?我试过了http:/api,http://localhost:3050但没有一个成功
这是我的 nginx.conf 文件
upstream client {
server client:3000;
}
upstream api {
server api:8080;
}
server{
listen 80;
location / {
proxy_pass http://client;
}
location /socket.io {
proxy_pass http://api;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location /api{
rewrite /api/(.*) /$1 break;
proxy_pass http://api;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 docker compose
version: "3"
services:
nginx:
restart: always
image: coco/nginx
build:
dockerfile: Dockerfile.dev …Run Code Online (Sandbox Code Playgroud) 我想在java中创建一个包含键和值的列表,并决定创建类似的东西
private static HashMap<String, Set<String>> battleTanks = new HashMap<String, Set<String>>();
Run Code Online (Sandbox Code Playgroud)
然后我试图在那里添加一些像battleTanks.put("keytest1","valuetest1")的值
但它给了我一个错误
方法put(String,Set)在HashMap>类型中不适用于参数(String,String)
那么我该如何添加这些值呢?
我试图弄清楚如何从路由控制器访问应用程序对象。在我的路线文件中我有
const apiController = require('../controllers/mainController')
module.exports = (app) => {
app.post("/stop",
apiController.stopFlow
);
app.post("/specificSearch",
apiController.initiateSearch);
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,我无法访问(app)这些控制器内部的对象,但是,如果我执行类似的操作
module.exports = (app) =>{
app.post('/stop', (req,res)=>{
console.log(app)
})
}
Run Code Online (Sandbox Code Playgroud)
然后一切正常,所以我很好奇有没有办法将它传递给我的apiController?我的apiController样子是这样的
module.exports = {
async stopFlow(req, res) {
console.log("Stop");
console.log(app)
},
}
Run Code Online (Sandbox Code Playgroud)
我能做什么来解决这个问题?