小编cec*_*ode的帖子

在react.js中相当于ng-if的是什么?

我将使用angular来做出反应,我正试图找出一个很好的反应替代angular的ng-if指令,我在这里渲染或根据条件渲染元素.以此代码为例.我正在使用打字稿(tsx)顺便说一句,但这应该不重要.

"use strict";

import * as React from 'react';

interface MyProps {showMe: Boolean}
interface MyState {}

class Button extends React.Component <MyProps, MyState>{
  constructor(props){
    super(props);
    this.state = {};
  }

  render(){
    let button;
    if (this.props.showMe === true){
       button = (
        <button type="submit" className="btn nav-btn-red">SIGN UP</button>
      )
    } else {
      button = null;
    }
    return button;

}
}
export default Button;
Run Code Online (Sandbox Code Playgroud)

这个解决方案有效,但是还有另一种通常用于实现这种效果的方法吗?我只是在猜测

reactjs

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

打字稿中的界面状态和道具起反应

我正在开发一个使用打字稿以及反应的项目,对两者都是新手.我的问题是关于打字稿中的界面以及它与道具和状态的关系.究竟发生了什么?除非我声明接口道具和状态,否则我的应用程序根本不会运行,但是我通过反应构造函数使用状态,并且我已经看到所有这些信息将进入"接口MyProps"或"接口MyStates"的示例例

"use strict";

import * as React from 'react'
import NavBar from './components/navbar.tsx'
import Jumbotron from './components/jumbotron.tsx';
import ContentPanel from './components/contentPanel.tsx';
import Footer from './components/footer.tsx';

interface MyProps {}
interface MyState {}
class Root extends React.Component <MyProps, MyState>  {
  constructor(props) {
    super(props);
    this.state = {
      ///some stuff in here

    };
  }
  render() {
    return (
      <div>
        <NavBar/>
        <Jumbotron content={this.state.hero}/>
        <ContentPanel content={this.state.whatIs}/>
        <ContentPanel content={this.state.aboutOne}/>
        <ContentPanel content={this.state.aboutTwo}/>
        <ContentPanel content={this.state.testimonial}/>
        <Footer content={this.state.footer}/>
      </div>
    )
  }
}
export default Root;
Run Code Online (Sandbox Code Playgroud)

(我已经删除了this.state中的内容,只是为了在这里发布).为什么我需要界面?这样做的正确方法是什么,因为我认为我是以jsx方式而不是tsx方式考虑这个问题.

jsx typescript reactjs tsx

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

如何添加多个className来响应组件?

我需要将一个className添加到从父节点传递下来的组件中,另一个className与它的父节点没有任何关系,但是与组件本身有关.

<div className={this.state.className} className={this.props.content.divClassName}>
      <div className={this.props.content.containerClassName}>
      <div className="row">
      <div className="col-sm-6 col-sm-offset-6">
        <p>{this.props.content.subTitle}</p>
        <h1 className={this.props.content.titleClassName}>{this.props.content.headerText}</h1>
        <p className={this.props.content.subTitleClassName}>{this.props.content.paragraph}</p>
        <p>{this.props.content.quote}</p>
        <Button showMe={this.props.content.showButton} buttonText={this.props.content.buttonText} />
      </div>
      </div>
      </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

当我尝试这个时,两个类都没有应用,我可以做其中一个或不同时做两个.我该如何实现这一目标?

reactjs

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

How to turn off Rails caching during development

I'm on Rails 5.2.2 and I'm building a web app that uses some static HTML, CSS, and JavaScript that I'm serving from inside of the public directory. Much of the time when I update a file it doesn't update in my browser when I refresh, but if I go into private browsing it works -- until it caches again and then I need to open a new private window.

How can I turn off caching for file in the public …

ruby caching ruby-on-rails static-files

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

尝试使用 sequelize 查询 postgres JSON 数据类型

我的表中有一个新创建的列,我需要在我的服务器控制器之一中进行查询。此列中的此数据将为 JSON 类型,并命名为“meta”。完成后看起来像这样

{
  "audit": {"date": 1465311598315, "user": 20191932891}
}
Run Code Online (Sandbox Code Playgroud)

目前,该表中的所有条目都有一个空的 JSON 列和一个 NULL 值。

在我的一个服务器控制器中,我需要获取所有元数据为 null 或 meta.audit.date 超过 90 天的条目。我的查询看起来像这样

  db.Question.findAll({
  where: {
    status: 'active',
    PassageId: {
      $eq: null
    },
    meta: {
      audit: {
        date: {
          $or: {
            $lte: threeMonthsAgo,
            $eq: null
          }
        }
      }
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

在这种情况下,三个月前是三个月前的日期作为数字。

没有返回任何结果,我在控制台中收到此错误:

Unhandled rejection SequelizeDatabaseError: operator does not exist: text <= bigint
Run Code Online (Sandbox Code Playgroud)

postgresql node.js sequelize.js

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

md对话框操作位于对话框的顶部而不是底部

按照他们网站上的示例进行自定义对话,得到了不同的结果.我的"动作"行的模式,而不是底部的顶部,看到这里

这是我使用的模板的html

<md-dialog aria-label="Mango (Fruit)"  ng-cloak>
  <form>
    <md-toolbar>
      <div class="md-toolbar-tools">
        <h2>Mango (Fruit)</h2>
        <span flex></span>
        <md-button class="md-icon-button" ng-click="cancel()">
          <md-icon md-svg-src="app/img/icons/ic_close_24px.svg" aria-label="Close dialog"></md-icon>
        </md-button>
      </div>
    </md-toolbar>
    <md-dialog-content>
      <div class="md-dialog-content">
        <h2>Using .md-dialog-content class that sets the padding as the spec</h2>
        <p>
          The mango is a juicy stone fruit belonging to the genus Mangifera, consisting of numerous tropical fruiting trees, cultivated mostly for edible fruit. The majority of these species are found in nature as wild mangoes. They all belong to the flowering …
Run Code Online (Sandbox Code Playgroud)

angular-material

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

使用环境变量进行本地序列化配置

我正在使用sequelize在我的项目的config.json文件中使用一个环境变量。我正在使用dotenv在本地设置环境变量。我的config.json文件看起来像这样

{
  "development": {
    "username": process.env.DB_USER,
    "password": process.env.DB_PASS,
    "database": process.env.DB_DATABASE,
    "host": process.env.DB_HOST,
    "dialect": "mysql"
  },
  "test": {
    "username": "root",
    "password": null,
    "database": "database_test",
    "host": "127.0.0.1",
    "dialect": "mysql"
  },
  "production": {
    "use_env_variable": "JAWSDB_URL",
    "dialect": "mysql"
  }
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是我无法在config.json文件中使用变量。在生产环境中,我可以使用“ use_env_varable”键,并在连接字符串中使用env变量。所以我想我要么需要一种方法来找出本地mysql数据库的组合连接字符串,要么需要一种使用config.json内部变量的方法。有什么办法吗?

mysql json environment-variables node.js sequelize.js

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

Ruby中的矩形交集

我正在努力理解这个程序,但我遇到了一些困难.我不理解的部分x_min,y_min,x_max,y_max.

我理解程序经过两个矩形与左下和右上坐标点,但是在做数组索引[0][0],[1][1]等等从何而来?

我对发生的事情感到困惑,所以解释会有所帮助.

# Write a function, `rec_intersection(rect1, rect2)` and returns the
# intersection of the two.
#
# Rectangles are represented as a pair of coordinate-pairs: the
# bottom-left and top-right coordinates (given in `[x, y]` notation).
#
# Hint: You can calculate the left-most x coordinate of the
# intersection by taking the maximum of the left-most x coordinate of
# each rectangle. Likewise, you can …
Run Code Online (Sandbox Code Playgroud)

ruby arrays intersection intersect

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

无法使用 href 或 ng-href 转到外部网址

我正在尝试使用动态 URL 将用户带到带有 AngularJS 的外部网站。但是,当点击该链接时,该链接会将用户带到我页面上的路线。

例如,如果我的网址是“mysite.com”,而我的链接是“google.com”。如果我单击此链接,使用hrefng-href,它会将我带到我网站上不存在的路线:“mysite.com/google.com”

如何导航到外部 URL?

我的代码示例:

<a href="{{ linkItem.link }}" target="_blank">View file</a>
Run Code Online (Sandbox Code Playgroud)

linkItem.link“google.com”。这对于任何网页都无法正常工作,即使对于具有硬编码 href 属性的网页也是如此。

html redirect href

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

如何在 golang 中输入混合类型数组?

我正在写一个我需要转换为 JSON 的地图,其中一个必需的值是一个混合类型的数组。

var models = map[string]interface{} {
   ...
   "req": [[0, "all", [0]]],
   ...
}
Run Code Online (Sandbox Code Playgroud)

有没有办法为这个嵌套数组分配类型?或者有没有比地图更好的方法来创建这个 JSON?

编辑:我认为越来越接近,不确定如何处理嵌套数组

var models = map[string]interface{} {
       ...
       "req": []interface{}{[[0, "all", [0]]]},
       ...
    }
Run Code Online (Sandbox Code Playgroud)

编辑:我想要创建的整个 JSON,我只是被困在“req”键上,但是因为它是被请求的:

{
    1388596687391: {
      veArs: [],
      name: 'Basic-f15d2',
      tags: ['Tag'],
      did: 1435588830424,
      usn: -1,
      req: [[0, 'all', [0]]],
      flds: [
        {
          name: 'Front',
          media: [],
          sticky: false,
          rtl: false,
          ord: 0,
          font: 'Arial',
          size: 20
        },
        {
          name: 'Back',
          media: [],
          sticky: false,
          rtl: false,
          ord: 1, …
Run Code Online (Sandbox Code Playgroud)

json types interface hashmap go

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

导航中的按钮而不是锚点?

我一直在阅读有关 Web 可访问性的内容,并了解到只有当用户将被带到另一个没有 JavaScript 的 URL 时才应该使用锚标记。但是只要发生其他一些行为,例如打开模态,就应该使用按钮。

所以我想知道是否可以或预期在导航中同时包含按钮和锚点。像这样的东西:

<nav>
  <a href="/">Home Page</a>
  <a href="/about">About Page</a>
  <button>Sign Up</button>
</nav>
Run Code Online (Sandbox Code Playgroud)

假设在这种情况下,注册按钮会启动一个模式或执行一些不会将用户带到不同 URL 的其他行为。两者都可以nav吗?我不关心样式,我会让这些看起来一致,但我想知道处理这样的事情最正确的方法是什么?

html accessibility semantic-markup hyperlink htmlbutton

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

不使用`transpose`转换数组

寻找一种方法来获取swingers下面的阵列并交换所有伙伴,同时保持男/女配对.我觉得令人困惑的是如何迭代二维数组

实施Swingers游戏.方法swingers应该采用一对数组的数组并返回相同类型的数据结构,并将这些数据混合起来.假设情侣阵列中的第一个项目是男性,第二个项目是女性.不要将一个人与自己性别的人配对(抱歉毁了你的乐趣).该程序的示例运行:

swingers([
  ["Clyde", "Bonnie"],
  ["Paris", "Helen"],
  ["Romeo", "Juliet"]
])
Run Code Online (Sandbox Code Playgroud)

ruby arrays

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