小编Was*_*and的帖子

WordPress get_template_part传递变量

有没有一种方法可以在wordpress中将变量传递给get_template_part():

<?php get_template_part( 'element-templates/front', 'top' ); ?>
<?php get_template_part( 'element-templates/front', 'main' ); ?>
Run Code Online (Sandbox Code Playgroud)

在front-top.php和front-main.php中(以上所述),我需要访问数字变量(每个部分一个不同的变量)。有没有一种方法可以将变量传递给上面的每个调用?

谢谢

variables wordpress

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

React - useState - 更新状态:值与函数

我想知道在引用先前状态时传递值和传递函数来更新功能组件中的状态是否有任何区别,如下所示:

import React, { useState } from "react";

export default function App() {
  const [counter, setCounter] = useState(0);
  const [counter2, setCounter2] = useState(0);

  const increaseCounter = () => {
    setCounter(counter + 1);
  };

  const increaseCounter2 = () => {
    setCounter2(prevState => prevState + 1);
  };

  return (
    <div className="App">
      <h1>Counter: {counter}</h1>
      <button type="button" onClick={increaseCounter}>
        Increase
      </button>
      <h1>Another Counter: {counter2}</h1>
      <button type="button" onClick={increaseCounter2}>
        Increase
      </button>
    </div>
  );
}
Run Code Online (Sandbox Code Playgroud)

官方文档在功能更新部分提到了这一点: https ://reactjs.org/docs/hooks-reference.html#function-updates

function Counter({initialCount}) {
  const [count, setCount] = useState(initialCount);
  return ( …
Run Code Online (Sandbox Code Playgroud)

reactjs use-state

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

Emacs Dired - Cx Cf创建一个新文件给了我现有文件的建议

我正在尝试在emacs中以dired模式创建一个文件.我在正确的目录中,当我按照其他地方的建议按Cx Cf并键入'img'(这是我要创建的文件的名称)时,它会尝试从其他目录中查找现有文件,包括模式'img' .然后我就像我按下回车一样卡住,它将打开包含其他目录中的模式'img'的第一个建议文件,TAB将只是查看建议.

请指教.

emacs dired

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

在React/js中从数组中查找唯一值

我是JavaScript的初学者,在ReactJS中是一个更大的初学者.以下大部分内容都是从教程中提取的,并且正在尝试对其进行调整.因此代码显示"标签"中的所有值(人物,地点,地点等).它将它显示为内联li元素,因为它将成为一个菜单.问题是它显示了所有元素的所有标记.我只是希望它能够捕获菜单的唯一"标记"值(例如,人物,地点,事物......).我试过_.uniq但它没有显示数组.谢谢.

import React from "react";
import GalleryHeader from './GalleryHeader';
import ImageEntry from './ImageEntry';
import _ from 'lodash';

export default class GalleryImages extends React.Component {

    renderItems() {
        return _.map(this.props.images, (image, index) => <ImageEntry key={index} {...image} />);
    }

  renderMenu() {
    return _.map(this.props.images, (image, index) => <GalleryHeader key={index} {...image} />);
  }


  render() {

    return (
      <div>
      <ul class="list-inline">
        {this.renderMenu()}
      </ul>
        {this.renderItems()}          
      </div>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

GalleryHeader

import React from "react";


export default class GalleryHeader extends React.Component {

  render() {

    return (
            <li>{this.props.tag}</li>
    ); …
Run Code Online (Sandbox Code Playgroud)

javascript uniq reactjs

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

在Linux上读取.fit文件

我如何在Linux上阅读Garmin的.fit文件。我想将其用于某些数据分析,但该文件是二进制文件。

我已经访问了http://garmin.kiesewetter.nl/,但是该网站似乎无法正常运行。

谢谢

converter fit-protocol

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

Reactjs - 访问变量

如何在下面的代码中访问变量bvar?另外,我何时将变量声明为:

一个状态

b)构造函数()和render()之间

c)inside render() - 我的理解是,如果变量可以改变,我会在这里设置它们,并且我想在每次组件渲染时设置它.所以,如果我知道某些事情根本没有改变,那它就是一个常数,我会在哪里设置它?

import React, {Component} from 'react';

export default class App extends Component {
  constructor(props) {
    super();
    // Set the initial grid in
    this.state = {
      value: 4,
      xsquares: 10,
      ysquares: 10
    };

    var bvar = "cat";
  }
  render() {
    var avar = [
      "Hydrogen",
      "Helium",
      "Lithium",
      "Beryl­lium"
    ];

    let cvar = "dog";

    return (
      // Add your component markup and other subcomponent references here.
      <div>
        <h1>Hello, World! {this.state.value}</h1>
        <h2>{this.state.xsquares}</h2>
        <h3>{avar[0]}</h3>
        <h4>{this.bvar}</h4>
        <h3>{cvar}</h3>
      </div>

    ); …
Run Code Online (Sandbox Code Playgroud)

variables reactjs

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

Pandas - 填充特定类别的平均值

我想用列的平均数填充,但仅用于与缺失值相同类别的代表

data = {'Class': ['Superlight', 'Aero', 'Aero', 'Superlight', 'Superlight', 'Superlight', 'Aero', 'Aero'],
        'Weight': [5.6, 8.6, np.nan, 5.9, 5.65, np.nan, 8.1, 8.4]}


    Class   Weight
0   Superlight     5.60
1   Aero           8.60
2   Aero           NaN
3   Superlight     5.90
4   Superlight     5.65
5   Superlight     NaN
6   Aero           8.10
7   Aero           8.40
Run Code Online (Sandbox Code Playgroud)

我知道我可以做到:

df.Weight.fillna(df.Weight.mean())
Run Code Online (Sandbox Code Playgroud)

但这将用整列的平均值填充缺失值。

以下将用 AERO 类别的平均值替换空值(这更好,但仍然不好,因为我必须分别为每个类别/类别做这件事)

df.Weight.fillna(df[df.Class == 'Aero'].Weight.mean())
Run Code Online (Sandbox Code Playgroud)

是否可以对其进行抽象,以便它自动获取当前行的 Class 并找到属于该类别的值的平均值并替换它而不对 Class 值进行硬编码?希望这是有道理的。

python pandas fillna

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

RN - typescript 样式作为道具

我正在逐渐将 RN 项目转移到 Typescript。我有一个关于声明作为 props 传递给组件的样式类型的问题。

组件内的 Props 定义如下:

interface Props {
  children: ReactNode;
  style?: ViewStyle;
}
Run Code Online (Sandbox Code Playgroud)

如果我只传递一个简单的样式对象就可以了,例如:

<Component style={{ marginTop: 1 }}>...children...</Component>
<Component style={styleObj}>....children...</Component>
Run Code Online (Sandbox Code Playgroud)

但如果我传递一系列样式,它就会失败:

<Component style={[styleObj, { marginTop: someVar }]}>...children...</Component>
Run Code Online (Sandbox Code Playgroud)

指定样式道具类型的最佳方法是什么?

编辑:TS 消息是:

TS2559: Type '({ flex: number; } | { marginTop: number; })[]' has no properties in common with type 'ViewStyle'.  Component.tsx(12, 3): The expected type comes from property 'style' which is declared here on type 'IntrinsicAttributes & Props'
Run Code Online (Sandbox Code Playgroud)

typescript react-native

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

JavaScript - 如何逐个字符显示文本

我正在尝试使用 JavaScript 逐个字符地显示从数组中获取的文本。我已经设法用阵列的一部分来做到这一点。我找不到换行并显示其余部分的方法。

var container = document.getElementById("container");

var notes = [
{scenario: 1, intro: "This is the introduction.", que: "What is the weight of ....?"},
{scenario: 2, intro: "This is the second scen.", que: "What is the second law of ...?"},
{scenario: 3, intro: "This is the third thing.", que: "What is the third law of ...?"},
];


function splTxt(txt) {
    // Split string into characters                                                                                                                                           
    t = txt.split('');
return t
}

function terminal(cl, i) {
// Create a div …
Run Code Online (Sandbox Code Playgroud)

html javascript arrays

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

反应本机弯曲高度

我有3个组件,我试图设置它们的高度(页眉,正文,页脚),但是在渲染时,每个组件的高度仅为其中包含的一行文本的高度。

import React from 'react';
import { View, Text } from 'react-native';
import Header from './Header';
import Body from './Body';
import Footer from './Footer';
import * as globalStyles from '../styles/global';


const HomeScreen = () => (
  <View style={{ flex: 1 }}>
    <Header style={{ flex: 1 }} title={'MyTitle'}>
      <Text>Component</Text>
    </Header>
    <Body style={{ flex: 3 }}>
      <Text>my body</Text>
    </Body>
    <Footer style={{ flex: 1 }}>
      <Text>my footer</Text>
    </Footer>
  </View>
);

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

应用程式

import React from 'react';
import { Provider } from …
Run Code Online (Sandbox Code Playgroud)

flexbox react-native

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