问题列表 - 第280411页

如何将变量传递给 React 中的内联 css 函数

我已经成功地在 React 中创建了类,并希望将随机生成的背景设置为 div 容器。名为 divStyle 的常量变量确实包含 CSS 函数 rbg() 但我找不到将变量从 this.state 传递到该函数的解决方案

import React from 'react';
import './ShopItem.css';

class ShopItem extends React.Component{
constructor(props){
    super(props);
    this.state = {
        r:Math.floor(Math.random() * 256),
        g:Math.floor(Math.random() * 256),
        b:Math.floor(Math.random() * 256)        
    }
}

componentDidMount() {
    console.log(this.state.r, this.state.g, this.state.b);
} 

render(){

    const divStyle = {
        background: "rgb()"
    };

    return(
        <div className="Item" style={divStyle} >
            {console.log("test")}
            {this.props.data}
        </div>
    );
};
};

export default ShopItem;
Run Code Online (Sandbox Code Playgroud)

css reactjs react-router

2
推荐指数
2
解决办法
7565
查看次数

如何轻松找出哪些测试失败

我用 测试我的代码go test ./... -v -short

不幸的是,-v它只在每次测试发生时将其打印出来,而不会像 Java 那样在底部留下结果摘要。这意味着,如果顶部某处的任何测试失败,我必须向上滚动并查找该单词FAIL或在文本编辑器中搜索它。

-failfast标志也没有帮助,因为我的一些测试在第一次测试失败后由于某种原因仍然被打印。

我真的不在乎测试在初始测试失败后是否运行。我只是希望能够轻松判断是否有任何测试失败,最好只在一个地方(例如,有多少测试通过或失败的摘要,或者通过查看所有测试是否通过的标志)。

有没有一种方法可以轻松判断是否存在测试失败,因为如果仍然存在测试失败,我不想意外地继续编码。

我使用的是 Windows 10 64 位。

更新:非常感谢@icza 的提示findstr。后来我意识到我还想看到错误描述以及测试失败,但不想运行go test两次。这是我为 CMD 提出的(不适用于 Powershell):

go test ./... -v -short > test-results.txt & findstr "FAIL _test" test-results.txt
Run Code Online (Sandbox Code Playgroud)

现在findstr应该报告测试失败以及错误描述。如果您想查看完整的测试结果,只需打开test-results.txt.

testing unit-testing go

8
推荐指数
2
解决办法
6095
查看次数

线性渐变边界修改

大家好,我想改变,我们需要将删除线更新为相同的对角线 - 以45度为中心.请在下面找到代码......

.Product__widths__button {
    background: #FFFFFF;
    border: 1px solid #333333;
    color: #333333;
    display: block;
    font-size: 16px;
    line-height: 42px;
    height: 42px;
    text-align: center;
    padding-left: 20px;
    padding-right: 20px;
}
.Product__widths__button.disabled {
    color: #D1D1D1;
    background: linear-gradient(to top left, #fff 38px, #D1D1D1, #fff 40px);
    border-color: #D1D1D1;
}
Run Code Online (Sandbox Code Playgroud)
<a id="width_1_1" class="Product__widths__button disabled"><span>W</span> (Wide)</a>
Run Code Online (Sandbox Code Playgroud)

这里想要显示如下图像

在此输入图像描述

如果我有更多需要,请告诉我.谢谢!!!

html css linear-gradients

2
推荐指数
1
解决办法
78
查看次数

iotop 不显示任何磁盘读取统计信息

我正在运行测试来检查磁盘读取统计信息。这是相同的代码:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

int main(int argc, char* argv)
{
int count=1000, size;
char block[4096]="0";
int fd = open("file1.txt",O_RDONLY | O_SYNC);
//int pid = getpid();
system("pid=$(ps -a | grep 'a.out' | awk '{print $1}'); iotop -bokp $pid > test1c.out &");
system("echo 'Starts reading in 10'");
srand(time(NULL));
system("sleep 1");
    while(count--){
      int random = (rand()%16)*666;
      printf("%d;",random);
      lseek(fd, random, SEEK_SET);
      size = read(fd,block,4096);
      printf("Number of bytes read: %d\n", size);
      fsync(fd);
      //printf("Read 4kb from the file.\n");
    }
system("sleep 1");
system("killall iotop"); …
Run Code Online (Sandbox Code Playgroud)

linux iostat

4
推荐指数
1
解决办法
2311
查看次数

静态对const局部变量有影响吗?

想象一下以下声明:

void foo(){
    const std::array<int, 80000> arr = {/* a lot of different values*/};
    //do stuff
}
Run Code Online (Sandbox Code Playgroud)

第二个:

void foo(){
    static const std::array<int, 80000> arr = {/* a lot of different values*/};
    //do stuff
}
Run Code Online (Sandbox Code Playgroud)

如果有的话,这两者之间可能存在哪些性能差异?这些解决方案是否有任何危险?

c++ static const

19
推荐指数
3
解决办法
1297
查看次数

Cookie 不随 CORS 网络请求发送

我正在尝试设置一个带有过期日期的 cookie:

response.Cookies.Append("theKey", value, new CookieOptions() { Expires = DateTime.Now.AddMonths(12) });
Run Code Online (Sandbox Code Playgroud)

cookie 存储在浏览器中,但不会在随后的跨站点 Web 请求中发送。

当我尝试设置没有Expires日期的 cookie 时,cookie 被发送,但它仅在浏览器打开时存储在浏览器中(会话 cookie)。

这是一个跨站点请求。调用该函数的 javascript 代码是:

var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", url, true);
xmlHttp.withCredentials = true;
xmlHttp.onreadystatechange = function () {
    if (this.readyState == 4 && this.status == 200) {
        //console.log(this.responseText);
    }
};
xmlHttp.send(null);
Run Code Online (Sandbox Code Playgroud)

有没有办法Expires在跨站点请求中发送包含日期的 cookie ?

客户端 Web 应用程序和函数应用程序(尝试设置 cookie)都使用 https。

这是设置带有过期日期的 cookie 的 HTTP 响应:

在此处输入图片说明

javascript cors .net-core asp.net-core-2.1

2
推荐指数
2
解决办法
5004
查看次数

如何在 NumberFormatter 中的逗号后显示零

我尝试使用 NumberFormatter 将我的号码格式化为字符串。这是我的代码:

\n\n
        let formater = NumberFormatter()\n        formater.groupingSeparator = " "\n        formater.numberStyle = .decimal\n\n\n        let formattedNumber = formater.string(from: (self.money as NSNumber))\n\n        self.currentMoneyLabel.text = "\\(formattedNumber!) \xe2\x82\xbd"\n
Run Code Online (Sandbox Code Playgroud)\n\n

我有类似 1 234 的号码,但我需要获得类似 1 234,00 的号码。

\n\n

如果我的数字在小数点之后,则该数字不为零,则一切正常。但如果逗号后面的数字为零,则不显示。如何使数字始终显示到百分之几,即使它是零?

\n

number-formatting swift

1
推荐指数
1
解决办法
1068
查看次数

Kotlin 协程:单线程中一次一个协程

考虑下面的代码,我试图用它Executors.newFixedThreadPool(1).asCoroutineDispatcher()来创建一个单线程调度程序;我希望其中的代码launch(singleThread){...}按顺序执行

预期结果应该如下所示,因为 async-block#2首先到达/获取singleThread

异步块#2
异步块#1
单线程块#2
单线程块#1
答案是3

但实际结果是

异步块#2
异步块#1
单线程块#1
单线程块#2
答案是3

single-thread-block-#2 和 single-thread-block-#1 似乎并行运行,singleThread在这里没有什么不同

import java.util.concurrent.Executors
import kotlinx.coroutines.*
import kotlin.system.*

val singleThread = Executors.newFixedThreadPool(1).asCoroutineDispatcher()

fun main() = runBlocking<Unit> {
    val time = measureTimeMillis {
        val one = async { // async block #1
            delay(200)
            println("async block #1")
            launch (singleThread) {
                delay(500)
                println("single thread block #1")
            }
            2
        }
        val two = async { // async block #2
            delay(100)
            println("async …
Run Code Online (Sandbox Code Playgroud)

multithreading android kotlin kotlin-coroutines

5
推荐指数
1
解决办法
7362
查看次数

PyCharm“无法获取部署服务器的远程凭据”

在配置远程解释器和部署之后,当 PyCharm 尝试从 requirements.txt

无法获取部署服务器的远程凭据

admin jetbrains-ide pycharm

13
推荐指数
3
解决办法
1万
查看次数

具有唯一索引的房间数据库迁移问题

我试图升级我的数据库版本,在最后一个版本中,该表在迁移室创建了一个唯一索引,给了我以下错误

预期的:

TableInfo{name='ALERT_STATUS', columns={resolution_time=Column{name='resolution_time', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}, status=Column{name='status', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, id=Column{name='id', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=1}, event_time=Column{name='event_time', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0}, is_uploaded=Column{name='is_uploaded', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, InvErrorCode=Column{name='InvErrorCode', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}, is_fault=Column{name='is_fault', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, FaultDetails=Column{name='FaultDetails', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}, code=Column{name='code', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0}, component=Column{name='component', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}}, foreignKeys=[], indices=[Index{name='index_ALERT_STATUS_code_event_time', unique=true, columns=[code, event_time]}]}
Run Code Online (Sandbox Code Playgroud)

成立:

TableInfo{name='ALERT_STATUS', columns={resolution_time=Column{name='resolution_time', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}, status=Column{name='status', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, id=Column{name='id', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=1}, event_time=Column{name='event_time', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0}, …
Run Code Online (Sandbox Code Playgroud)

sqlite android database-migration android-room

5
推荐指数
1
解决办法
1028
查看次数