小编cra*_*eld的帖子

使用 Diesel 的 `belongs_to` 属性时“使用未声明的类型或模块”

我松散地遵循 Diesel 的入门指南尝试设置关系数据库,但在编译时出现以下错误:

error[E0433]: failed to resolve: use of undeclared type or module `birds`
 --> src/models.rs:9:12
  |
9 | pub struct Bird {
  |            ^^^^ use of undeclared type or module `birds`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.
error: Could not compile `prrr_gql`.

Run Code Online (Sandbox Code Playgroud)

这是二进制文件:

extern crate prrr_gql;
extern crate diesel;

use self::prrr_gql::*;
use self::models::*;
use self::diesel::prelude::*;

fn main() {
    use prrr_gql::schema::cats::dsl::*;
    use prrr_gql::schema::birds::dsl::*;

    let connection = establish_connection();
    let …
Run Code Online (Sandbox Code Playgroud)

rust rust-diesel

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

TypeError:req.checkBody不是函数

我正在尝试在注册系统中实现一些验证,但我收到错误:

     TypeError: req.checkBody is not a function
Run Code Online (Sandbox Code Playgroud)

来自以下代码:

module.exports = function(app, express) {
  var express = require('express');
  var api = express.Router();

  // post users to database
  api.post('/signup', function(req, res) {
    var email = req.body.email;
    var password = req.body.password;
    var password2 = req.body.password2;
    var key = req.body.key;

    // Validation
    req.checkBody('email', 'Email is required.').notEmpty();
    req.checkBody('email', 'Email is not valid').isEmail(); 
    req.checkBody('password', 'Password is required').notEmpty();
    req.checkBody('password2', 'Passwords do not match').equals(req.body.password);

    var errors = req.validationErrors();

    if(errors) {
      res.render('register', {
        errors: errors
      });
    } else { …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express

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

RuntimeError:针对API版本0xa编译的模块,但此版本的numpy为0x9

我正在浏览New Coder的API教程(这个),当我尝试运行程序时出现以下错误:

RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9Traceback (most recent call last):
  File "api.py", line 7, in <module>
import matplotlib.pyplot as plt
  File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
  File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.artist as martist
  File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
  File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: numpy.core.multiarray failed to import
Run Code Online (Sandbox Code Playgroud)

我知道这不是我的代码,因为我尝试使用示例代码运行它并且遇到了同样的问题.我在这里看到的一个答案是尝试Numpy …

python api numpy matplotlib

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

在与其他元素相同的行上显示 React 组件

我试图让我构建的 React 组件与文本的其余部分显示在同一行,但它始终显示在与其余元素不同的行上。

这是我的反应代码:

<div className={styles['top']}>
    <span>WHAT PEOPLE ARE SAYING</span>
    <div className={`pull-right ${styles['right']}`}>
      <span className={`${styles['rating-words']}`}>{ratingWords}</span>
      <Rating className={`${styles['overall-stars']}`}
              percentage={this.state.overallPercentage}
              color={"#00c18a"}
              under={"white"}
      />

    </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

和 .scss:

.top {
  margin: 30px 0;
  font-weight: bold;
  .right {
    display: inline-block;
    flex-direction: row;
  }
  .rating-words {
    text-transform: uppercase;
  }
}
Run Code Online (Sandbox Code Playgroud)

最后,看一下它的样子:

在此输入图像描述

“非常好”和评级星星应该在同一条线上。知道如何解决这个问题吗?

javascript sass reactjs

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

Promise.then不是一个函数 - 在React中处理多个API调用

我正在使用react-select来自动完成搜索栏中的选项.搜索栏以两种类别之一显示结果,具体取决于它命中的API端点.

现在,它可以处理来自任何一个点或另一个点的数据,但是我无法将数据从两个端点返回到react-select的loadOptions参数.

这个关于多个API调用的答案,我决定使用promises一次返回所有数据,但是我得到了错误Uncaught TypeError: promise.then is not a function at Async.loadOptions

这是我的代码loadOptions:

const getAsync = (tripId, destinationIndex, input) => {
  if (!input) {
    return { options: [] }
  }

  function getMusement(input) {
    return new Promise(function(resolve, reject) {
      TVApi.musement.autocomplete(input)
        .then((m) => {
          const musementOptions = m.map(musementToOption).slice(0, 4)
          return resolve(musementOptions)
        })
    })
  }

  function getFourSquare(tripId, destinationIndex, input) {
    return new Promise(function(resolve, reject) {
      TVApi.spot.autocomplete(tripId, destinationIndex, input)
        .then((fs) => {
          const fsOptions …
Run Code Online (Sandbox Code Playgroud)

javascript promise reactjs react-select

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

Diesel 的属性 `primary_key` 目前对于编译器来说是未知的

我正在尝试在 Diesel 中使用该#[primarykey()]宏,但收到一条未知错误。根据我的发现,添加#![feature(primary_key)]应该可以解决问题,但事实并非如此。

库文件

#[macro_use]
extern crate diesel;
extern crate dotenv;

pub mod schema;
pub mod models;

use diesel::prelude::*;
use diesel::pg::PgConnection;
use dotenv::dotenv;
use std::env;

pub fn establish_connection() -> PgConnection {
    dotenv().ok();

    let database_url = env::var("DATABASE_URL")
        .expect("DATABASE_URL must be set");
    PgConnection::establish(&database_url)
        .expect(&format!("Error connecting to {}", database_url))
}
Run Code Online (Sandbox Code Playgroud)

模型.rs

#![feature(primary_key)]

extern crate diesel;

#[derive(Queryable, Debug)]
#[primary_key(user_id)]
pub struct User {
    pub user_id: i32,
    pub email: String,
    pub password: String,
    pub bio: String,
    pub verified: bool,
}
Run Code Online (Sandbox Code Playgroud)

我也尝试添加 …

rust rust-diesel

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

无法使用 defaultValue 设置 React 状态

我正在尝试使我的组件中的用户配置文件可编辑。现在,当用户单击“编辑”时,配置文件将替换为一个表单,该表单将他们输入的值作为默认值。但是,如果他们只更新一个字段,其他字段将被重写为空值,而不是将默认值传递给状态。

有没有办法将 defaultValue 传递给状态?我也试过 value={} 但是这个值根本没有改变。

我试图避免每个输入都有一个“编辑”按钮。

class AccountEditor extends Component {
  constructor() {
    super()
    this.state = {
      isEditing: false,
      profile: {
        firstName: '',
        lastName: '',
        city: '',
        email: '',
        bio: '',
      }
    }
  }

  toggleEdit(event) {
    event.preventDefault()
    this.setState({
      isEditing: !this.state.isEditing
    })
  }

  updateProfile(event) {
    let updatedProfile = Object.assign({}, this.state.profile)
    updatedProfile[event.target.id] = event.target.value

    this.setState({
      profile: updatedProfile
    }
  }

  submitUpdate(event) {
    event.preventDefault()
    this.props.onUpdate(this.state.profile)
    this.setState({
      isEditing: !this.state.isEditing
    })
  }

  render() {
    let profile = this.props.profile
    let content = null

    if (this.state.isEditing == …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

使用API​​调用更新React-Redux中的组件状态

我正在尝试设置一个React应用程序,其中单击一个组件中的地图标记会使用数据库中的数据重新呈现页面上的另一个组件并更改URL.它有效,但不是很好.我无法弄清楚如何从Redux获取状态并从API中获得响应,以适应React生命周期.

有两个相关的问题:

FIRST:注释掉的行"//APIManager.get()......"不起作用,但它下面的行上的黑客联合版本确实如此.

SECOND:我是console.log()的行 - 无限响应日志,并向我的数据库发出无限的GET请求.

这是我的组件如下:

class Hike extends Component {
  constructor() {
    super()
    this.state = {
      currentHike: {
        id: '',
        name: '',
        review: {},
      }
    }
  }

  componentDidUpdate() {
    const params = this.props.params
    const hack = "/api/hike/" + params
    // APIManager.get('/api/hike/', params, (err, response) => { // doesn't work
    APIManager.get(hack, null, (err, response) => { // works
      if (err) {
        console.error(err)
        return
      }
      console.log(JSON.stringify(response.result)) // SECOND

      this.setState({
        currentHike: response.result
      })
    })
  }

  render() {
    // Allow for fields …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-redux

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