小编Acy*_*Acy的帖子

按住 Ctrl 键拖动时出错

我制作了两个片段,相同的代码,一个在JSFiddle 中,一个作为 Stack Snippet(见下文)。出于某种原因,Ctrl键 + 拖动会产生不同的结果。

如果我按住Ctrl键,JSFiddle 不会触发我的拖动事件,但 Stack Snippet 会。有人可以尝试运行这些吗?我以为这是浏览器或计算机问题,但也许不是。

var svg = d3.select('svg');

var drag = d3
      .drag()
      .on("start", function() {
        console.log("start");
      })
      .on("drag", function() {
        console.log("dragging");
      })
      .on("end", function() {
        console.log("eneded");
      });

svg.append("g").call(drag).append("circle").attr("cx", 10).attr("cy", 10).attr("r", 8)
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.2.0/d3.min.js"></script>
<svg></svg>
Run Code Online (Sandbox Code Playgroud)

javascript d3.js

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

React 在函数内部设置状态

我正在使用一些 d3 进行可视化,并决定也使用 reactstrap。基本上点击 d3 中的一个圆圈会导致 reactstrap 元素 Collapse 出现。

我没有找到 setState 的任何运气......我在 componentDidMount() 内部执行我所有的反应代码,我有一个函数 update(),在更新中,我有一个名为 click 的函数,当单击触发器,它会:

this .setState({ 折叠: !this.state.collapse });

它不起作用,而且我缺乏基本的 JS 来解释为什么,我假设this关键字指的是函数更新而不是我的组件“树”?

代码:

import React, { Component } from "react";
import * as d3 from "d3";
import { hierarchy, tree } from "d3-hierarchy";

import { Collapse, Button, CardBody, Card } from "reactstrap";

class Tree extends Component {
  constructor(props) {
    super(props);
    this.state = { collapse: false };
    this.updateWindowDimensions = this.updateWindowDimensions.bind(this);
    //this.toggle = this.toggle.bind(this);
  }

  componentDidMount() …
Run Code Online (Sandbox Code Playgroud)

javascript d3.js reactjs

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

Django:在基于类的视图中的get_context_data中放置更多上下文

我确实知道要在django的listview中放置更多上下文,我们可以这样:

def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        b = 9
        context['num'] = b
        return context
Run Code Online (Sandbox Code Playgroud)

这样,我们就可以在模板文件中使用num了。

但是,假设我想将变量放置在上下文中,该怎么办?

b = 9
a = 10 
context['a', 'b'] = a, b
Run Code Online (Sandbox Code Playgroud)

然后在我的html模板中通过直接调用{{a}}或{{b}}来引用它,没有错误显示,但是也没有任何显示。

我想我对基本字典有一些误解,而django给它增加了混乱,因为似乎您不能在{{}}内使用()或[],有人可以回答为什么我们不能使用()或{]在{{}}内的html代码内?

django

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

OpenCV2 imwrite is writing a black image

I am messing around with opencv2 for neural style transfer... In cv2.imshow("Output", output), I am able to say my picture. But when I write output to file with cv2.imwrite("my_file.jpg", output). Is it because my file extension is wrong? When I do like cv2.imwrite("my_file.jpg", input) though, it does show my original input picture. Any ideas? Thank you in advance.

# import the necessary packages
from __future__ import print_function
import argparse

import time
import cv2
import imutils

import numpy as np
from …
Run Code Online (Sandbox Code Playgroud)

opencv machine-learning computer-vision

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