小编use*_*513的帖子

如何将一个组件的值发送到react js中的另一个组件?

你能告诉我如何在按钮点击时在第二个组件上发送输入字段值.我在第一个组件中有一个按钮和输入字段.单击按钮我需要将输入字段值发送到第二个组件

这是我的代码 http://codepen.io/naveennsit/pen/GZbpeV?editors=0010

var { Router, Route,browserHistory } = ReactRouter
class First extends React.Component{
  sendValue(){
    browserHistory.push('/second');
  }
  render(){
    return (<div>
    <input type='text' />
      <button onClick={this.sendValue}>send</button>
    </div>)
  }
}

class Second extends React.Component{
  render(){
    return <div>second component</div>
  }
}
class Main extends React.Component{
  render(){
    return (
     <Router history={browserHistory}>
          <Route path='/' component={First}></Route>  
          <Route path='/second' component={Second}></Route>  
    </Router>)
   }
}
React.render( <Main />,document.getElementById('app'));
browserHistory.push('/')
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-router

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

如何消除此错误(出现错误 $localStorage.getItem is not a function)?

我正在尝试将数据保存在本地存储上,但收到错误$localStorage.getItem is not a function。实际上我正在使用 ionic 框架。我需要持久存储数据并从持久性获取数据。我使用 ngstorage.js 。我还包括该模块,但出现未定义的错误

在此行中出现错误 return $localStorage.getItem("list"); 这是我的代码 https://dl.dropbox.com/s/l2dtrxmnsurccxt/www.zip?dl=0

(function(){
    'use strict';

    angular.module('app.stationselect').factory('stationListDownload', stationListDownload);
    stationListDownload.$inject=['$http','$localStorage']
    function stationListDownload($http,$localStorage){
        var list;
        return {
            getDownloadList: function(){
               return $http.get("http://caht.firstrail.com/FGRailApps/jservices/rest/stationList");
            },
            getlist :function(){
               return $localStorage.getItem("list");
            },
            setList :function (list){
                this.list=list;
            }
        }

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

编辑

 var list= stationListDownload.getlist();
    if(list==null ||typeof list=='undefined' ){
        stationListDownload.getDownloadList().then(function(data){
            $scope.loadingIndicator.hide();
            console.log("success")
            $localStorage.setItem("list",JSON.stringify(data));
        },function(error){
            console.log("error")
        })
    }else {
        console.log('else condition')
       cosole.log(list);
    }
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-directive angularjs-scope ionic-framework

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

如何在角度2中将一条路线导航到另一条路线

我制作了角度2的两个不同组件.我正在学习这个链接的路由 https://angular.io/docs/ts/latest/tutorial/toh-pt5.html

我制作了两个组件.在第一个组件中,我有一个按钮,我想移动到第二个组件

这是我的代码 https://plnkr.co/edit/GBOI9avZaPGaxaLQbtak

我定义这样的路线

    const routes =[
      {
        path: 'ft',
        component: First
      },
      {
        path: 'sd',
        component: Second
      }
    ]

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ App ],
  bootstrap: [ App,First ,Second]
}) 
Run Code Online (Sandbox Code Playgroud)

我在用 <router-outlet>

但我无法将一个组件移动到另一个组件

angular2-routing angular

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

为什么我的箭头函数有原型属性?

如文档 https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions中所述

箭头函数没有原型属性

但是当我把它放在小提琴上时,它为什么会给出一个objecthttp://es6console.com/iwyii5vm/

为什么要给对象?

var Foo = () => {};
console.log(Foo.prototype); 
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 babeljs arrow-functions

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

如何在xslt中减去值?

您能否告诉我如何使用变量减去xslt中的值?

这是我的代码:

<xsl:variable name="currentCurpg" select="1"/>
<xsl:variable name="tCurpg" select="($currentCurpg-1)"/>
Run Code Online (Sandbox Code Playgroud)

该变量tCurpg应为zero0

为什么我出错了?

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

    <xsl:template match="/">
      <hmtl>
        <head>
          <title>New Version!</title>
        </head>
         <xsl:variable name="currentCurpg" select="1"/>
          <xsl:variable name="tCurpg" select="($currentCurpg-1)"/>
     <xsl:value-of select="$tCurpg"/>

      </hmtl>
    </xsl:template>


</xsl:transform>
Run Code Online (Sandbox Code Playgroud)

我期望输出zero

xml xslt jquery xslt-1.0

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

添加 div 时,对象作为 React 子对象无效?

我只是渲染数据并在两者之间显示,divs但我收到错误

对象作为 React 子对象无效(找到:Wed Dec 09 1998 00:00:00 GMT+0530(印度标准时间))。如果您打算渲染一组子项,请改用数组。

<Fragment key={String(index) + String(i)}>
                    <div>{displaytext}</div>
                    <div>{value}</div>
                  </Fragment>
Run Code Online (Sandbox Code Playgroud)

唯一的问题是在这条线上,<div>{value}</div>如果我删除这条线,一切正常。如果我添加这条线,为什么会出现上述错误?这是我的代码 https://codesandbox.io/s/ooj2wowy9q

javascript reactjs react-redux

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

功能组件不能具有引用。您是要使用React.forwardRef()吗?

嗨,我正在尝试从计算机中选择文件形式,并在输入字段中显示文件名,但出现此错误

功能组件不能具有引用。你是说要使用React.forwardRef()

https://stackblitz.com/edit/react-aogwkt?file=bulk.js

这是我的代码

import React, { Component } from "react";
import {
  Button,
  Dialog,
  DialogActions,
  DialogContent,
  DialogTitle,
  FormControl,
  IconButton,
  Input,
  InputAdornment,
  withStyles
} from "@material-ui/core";
import Attachment from "@material-ui/icons/Attachment";
import CloudDownload from "@material-ui/icons/CloudDownload";
const BulkUpload = props => {
  const { classes } = props;
  return (
    <div className="App">
      <input
        id="file_input_file"
        className="none"
        type="file"
        ref={'abc'}
      />
      <Input
        id="adornment-attachment"
        type="text"
        fullWidth

        endAdornment={
          <InputAdornment position="end">
            <IconButton
              aria-label="Toggle password visibility"
              onClick={e => {
              // this.refs['abc'].click();
              }}
              className="login-container__passwordIcon"
            >
              <Attachment />
            </IconButton>
          </InputAdornment>
        } …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs redux

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

如何使用sequelize从响应中删除属性?

const User = sequelize.define('user', {
    // attributes
    firstName: {
        type: Sequelize.STRING,
        allowNull: false
    },
    lastName: {
        type: Sequelize.STRING
        // allowNull defaults to true
    }
});

const Project = sequelize.define('project', {
    // attributes
    projectName: {
        type: Sequelize.STRING,
        allowNull: false
    }
});
User.belongsToMany(Project,{as:'Projects',through:'user_project'});
Project.belongsToMany(User,{as:'Users',through:'user_project'});
Run Code Online (Sandbox Code Playgroud)

像这样获取数据

app.use('/get', (req, res) => {
    User.findAll({
        attributes: ['firstName'],
        include: [{
         model:Project,
            as:'Projects',
            attributes: ['projectName']
        }]}).then((result) => {
        res.json(result)
    })
})
Run Code Online (Sandbox Code Playgroud)

得到这样的回应

 [{
    "firstName": "naveen",
    "Projects": [
      {
        "projectName": "EV",
        "user_project": {
          "createdAt": "2019-07-21T06:17:49.119Z",
          "updatedAt": "2019-07-21T06:17:49.119Z",
          "userId": 1, …
Run Code Online (Sandbox Code Playgroud)

javascript node.js sequelize.js

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

如何在外部点击时禁用隐藏弹出窗口?

我想知道如何防止从外面点击弹出窗口时隐藏弹出窗口?单击时,将显示弹出窗口.之后我需要防止它隐藏起来.当我在弹出窗口外面点击时,我的弹出窗口隐藏起来.有办法防止这种情况吗?

Codepen URL:http://codepen.io/anon/pen/WvYwqZ

$ionicPopover.fromTemplateUrl('my-popover.html', {
    scope: $scope
  }).then(function(popover) {
    $scope.popover = popover;
  });


  $scope.openPopover = function($event) {
    $scope.popover.show($event);
  };
  $scope.closePopover = function() {
    $scope.popover.hide();
  };
Run Code Online (Sandbox Code Playgroud)

javascript angularjs ionic-framework

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

如何显示行的交替红色和绿色?

我在反应中使用react table。我从这里学习 https://github.com/tannerlinsley/react-table/tree/v6#codesandbox-examples 和从这里 https://www.npmjs.com/package/react-table

我想显示我的行交替颜色“红色”和“绿色”,每个单元格上都有黑色边框。我们可以在反应表中显示吗?

这是我的代码 https://codesandbox.io/s/ecstatic-banzai-zp54o

在此处输入图片说明

css reactjs react-table

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