小编use*_*909的帖子

如何在React中访问DOM元素?React中document.getElementById()的等价是什么

如何在react.js中选择某些条形图?

这是我的代码:

var Progressbar = React.createClass({
    getInitialState: function () {
        return { completed: this.props.completed };
    },
    addPrecent: function (value) {
        this.props.completed += value;
        this.setState({ completed: this.props.completed });
    },

    render: function () {

        var completed = this.props.completed;
        if (completed < 0) { completed = 0 };


        return (...);
    }
Run Code Online (Sandbox Code Playgroud)

我想使用这个React组件:

var App = React.createClass({
    getInitialState: function () {

        return { baction: 'Progress1' };
    },
    handleChange: function (e) {
        var value = e.target.value;
        console.log(value);
        this.setState({ baction: value });
    },
    handleClick10: function (e) …
Run Code Online (Sandbox Code Playgroud)

javascript getelementbyid reactjs

147
推荐指数
5
解决办法
26万
查看次数

如何在Python中设置matplotlib中的"后端"?

我是matplotlib的新用户,我的平台是Ubuntu 10.04 Python 2.6.5

这是我的代码

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt 
plt.plot([1,2,3])
Run Code Online (Sandbox Code Playgroud)

错误是:

/usr/local/lib/python2.6/dist-packages/matplotlib/backends/__init__.py:41: UserWarning: 
Your currently selected backend, 'agg' does not support show().
Please select a GUI backend in your matplotlibrc file ('/usr/local/lib/python2.6/dist-packages/matplotlib/mpl-data/matplotlibrc')
or with matplotlib.use()
  (backend, matplotlib.matplotlib_fname()))
Run Code Online (Sandbox Code Playgroud)
  • 我安装了Anti-Grain Geometry库,apt-get install libagg但它不起作用.
  • 我尝试使用后端的其他参数,如'GTK'和'TkAgg'.
  • 我安装了python-gtk2-dev包,但仍然出现错误.
  • 谁能告诉我一个可执行的后端参数及其依赖库?

这是错误:

>>> matplotlib.use('GTK')
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/pyplot.py", line 95, in <module>
    new_figure_manager, draw_if_interactive, show = …
Run Code Online (Sandbox Code Playgroud)

python linux graphics matplotlib

74
推荐指数
6
解决办法
14万
查看次数

如何更改模板数据库集合编码

我想通过以下方式构建新的postgreSQL数据库:

CREATE DATABASE newdb
WITH OWNER = postgres
   ENCODING = 'UTF8'
   TABLESPACE = pg_default
   LC_COLLATE = 'zh_CN.UTF-8'
   CONNECTION LIMIT = -1;
Run Code Online (Sandbox Code Playgroud)

而错误是:

错误:新排序规则(zh_CN.UTF-8)与模板数据库的排序规则不兼容(en_US.UTF8)
提示:使用与模板数据库中相同的排序规则,或使用template0作为模板.

如何更改模板数据库集合?

postgresql postgresql-9.2

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

超时时终止或终止子进程?

我想尽快重复执行一个子进程.但是,有时这个过程需要很长时间,所以我想杀掉它.我使用signal.signal(...)如下所示:

ppid=pipeexe.pid
signal.signal(signal.SIGALRM, stop_handler)

signal.alarm(1)
.....
def stop_handler(signal, frame):
    print 'Stop test'+testdir+'for time out'
    if(pipeexe.poll()==None and hasattr(signal, "SIGKILL")):
         os.kill(ppid, signal.SIGKILL)
         return False
Run Code Online (Sandbox Code Playgroud)

但有时这段代码会试图阻止下一轮执行.停止测试/ home/lu/workspace/152/treefit/test2for time out/bin/sh:/ home/lu/workspace/153/squib_driver:not found ---这是下一次执行; 该程序错误地阻止它.

有谁知道如何解决这个问题?我想及时停止不执行1秒钟.sleep(n)经常等待n秒.我不希望我希望它可以执行不到1秒

python subprocess signals timeout kill

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

"DSR已开启;请勿发送DTR"错误

当我将笔记本电脑连接到我的Android手机时,电脑远离我这个错误:

1827    Data Router             usb connection is true
1827    Data Router             DSR is on Don't send DTR on
Run Code Online (Sandbox Code Playgroud)

我的手机是带有Android 4.03的Galaxy II.

根据我的搜索:

DSR=Data Set Ready    DCE (Data Carrier Detect) is ready to receive commands or data.
DTR=Data Terminal Ready  Indicates presence of DTE to DCE.
Run Code Online (Sandbox Code Playgroud)

android serial-communication

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

ts-node 执行带有模块导入和模块定义的打字稿

我尝试通过打字稿初始化数据库库。

我的 ts 是这样的:

import { User, UserRole } from '../entity/User';
import crypto from 'crypto';
import {dbManager, pwhash } from '..';

async function inituser() 
{
    const user = new User();
    user.email = 'sheng.lu@mq.edu.au';
    user.own_organization = []
    user.salt = crypto.randomBytes(16).toString('hex');
    user.password = pwhash("password", user.salt);
    user.role = UserRole.admin;
    await dbManager.save(user);
    const duser = await dbManager.findOne(User);
    return duser;
}
const duser = inituser();

console.log("Loaded users: ", duser);
Run Code Online (Sandbox Code Playgroud)

当我尝试通过 ts-node 运行脚本时:

npx ts-node db/initializers/inituser.ts
Run Code Online (Sandbox Code Playgroud)

有错误:

SyntaxError: Cannot use import statement outside a module
    at …
Run Code Online (Sandbox Code Playgroud)

typescript tsconfig package.json ts-node

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

我无法在playframework 2.3.0中导入过滤器

我使用playframework 2.3.0,最近我想添加CSRFFilter

当我在global.scala中导入csrf时:

import play.filters.csrf._
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

[错误] G:\ testprojects\app\Global.scala:7:对象过滤器不是包播放的成员[error] import play.filters.csrf._

我的plugin.sbt是

...
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.0")
...
Run Code Online (Sandbox Code Playgroud)

我使用Build.scala而不是build.sbt

lazy val root  = Project("root", base = file(".")).enablePlugins(PlayScala)
.settings(baseSettings: _*)
.settings(libraryDependencies++=appDependencies)
.settings(
  scalaVersion := "2.11.1",
  version := "1.0"

)
Run Code Online (Sandbox Code Playgroud)

scala servlet-filters playframework playframework-2.3

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

如何在python中获取最大堆

我在python中使用heapq模块,我发现我只能使用min heap,即使我使用reverse = True

我仍然得到最小的顶级堆

from heapq import *

h=[]
merge(h,key=lambda e:e[0],reverse=True)
heappush(h, (200, 1))
heappush(h, (300,2))
heappush(h, (400,3))
print(heappop(h))
Run Code Online (Sandbox Code Playgroud)

我仍然得到结果:

(200, 1)
Run Code Online (Sandbox Code Playgroud)

我想得到结果:

(400,3)
Run Code Online (Sandbox Code Playgroud)

怎么做?

这是最小的元素.我想要流行最大的emelment?

ps:这是问题的一部分找到max然后分成几个元素然后把它放回堆中.

python heap max-heap

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

打字稿类型 'string | string[]' 不能分配给类型 'string',什么是 'string | 字符串[]'类型?如何将它们转换为字符串?

当我做打字稿时:

let token = req.headers['x-access-token'] || req.headers['authorization'] as string;
Run Code Online (Sandbox Code Playgroud)

我有一个错误:

Argument of type 'string | string[]' is not assignable to parameter of type 'string'
Run Code Online (Sandbox Code Playgroud)

任何人都知道什么是 'string | 字符串[]'类型?我的意思是如果我想在打字稿中使用两个字符串的逻辑“或”。怎么做?

以及如何转换 'string | string[]' 类型到字符串类型?

string typescript logical-or

9
推荐指数
3
解决办法
8202
查看次数

如何在Slick2.0中使用DateTime?

我想DateTime在Slick 2.0模型中使用.我用jodatime:

我添加了依赖项Build.scala:

   "joda-time" % "joda-time"    % "2.3",
   "org.joda"  % "joda-convert" % "1.6"
Run Code Online (Sandbox Code Playgroud)

然后我做:

 class Comment(tag:Tag) extends Table[(Long, Int, Int, String, Int, DateTime)](tag,"Comment"){
  def id=column[Long]("ID", O.PrimaryKey)
  def rate=column[Int]("rate")
  def sub=column[Int]("subject")
  def content=column[Int]("cotent")
  def user_ID=column[Int]("user")
  def time=column[DateTime]("time")   //-----------an error here
  def * = (id, rate,sub, content, user_ID, time)
}
Run Code Online (Sandbox Code Playgroud)

错误是:

 could not find implicit value for parameter tm: scala.slick.ast.TypedType[org.joda.time.LocalDate]
Run Code Online (Sandbox Code Playgroud)

我添加了joda-convert jar但它似乎不起作用.如何在Slick模型类中添加DateTime?

scala jodatime slick slick-2.0

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