我正在使用 react-stripe-elements 创建一个用于支付的令牌。但是,根据文档,当卡片形式包含在 Elements 组件中时,它应该自动选择要标记化的条纹元素。
但是,在这种情况下,我们会遇到错误
You must provide a Stripe Element or a valid token type to create a Token.
Run Code Online (Sandbox Code Playgroud)
这是代码:
import React from 'react';
import {CardCVCElement, CardExpiryElement, CardNumberElement, PostalCodeElement, StripeProvider, Elements} from 'react-stripe-elements';
class CheckoutForm extends React.Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(ev) {
ev.preventDefault();
this.props.stripe.createToken({email: 'test@test.com'}).then(({token }) => {console.log('Received Stripe token:', token)});
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<label>
Card details
<CardNumberElement />
<CardExpiryElement />
<CardCVCElement />
<PostalCodeElement />
</label>
<button>Confirm order</button>
</form> …Run Code Online (Sandbox Code Playgroud) javascript stripe-payments reactjs stripe.js react-stripe-elements
我正在使用Omniauth-facebook和Devise-token-auth构建一个Rails-API,其中Angular和ng-token-auth用于前端.但是当用facebook登录时,我会看到错误:
undefined local variable or method `flash' for #<Devise::OmniauthCallbacksController:0x007fd027a51e10>
Run Code Online (Sandbox Code Playgroud)
似乎omniauth自动使用闪存中间件但是rails-api不包括这个,并且我没有成功禁用使用omniauth的flash.我的配置如下:
application.rb中:
require File.expand_path('../boot', __FILE__)
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module PathfinderApi
class Application < Rails::Application
config.active_record.raise_in_transactional_callbacks = true
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*'
resource '*', :headers => :any, …Run Code Online (Sandbox Code Playgroud) 我有以下一组人:
const FIRST_ARRAY = [
{
name: 'Simon',
age: 32,
occupation: 'Student'
},
{
name: 'Vera',
age: 22,
occupation: 'Developer'
}
];
Run Code Online (Sandbox Code Playgroud)
我想过滤数组以生成基于“过滤器”对象的单独数组。
例如,如果我的过滤器是:
const FILTERS = {
age: 32,
name: 'John',
occupation: ''
};
Run Code Online (Sandbox Code Playgroud)
新数组应该为空,因为数组中没有人拥有 32 和 John 的组合。但是,如果我的过滤器是:
const FILTERS = {
age: 32,
name: 'Simon',
occupation: ''
}
Run Code Online (Sandbox Code Playgroud)
返回的新人员数组将是:
const NEW_ARRAY = [
{
name: 'Simon',
age: 32,
occupation: 'Student'
}
];
Run Code Online (Sandbox Code Playgroud)
如何通过迭代“过滤器”对象值来过滤人员数组?请记住,过滤器键和值会一直动态变化。
当尝试设置SCSS以使用Webpack在我的React应用程序上运行样式时,出现以下错误:
Module not found: Error: Can't resolve 'style' in '/Users/sachinkaria/Workspace/GC' @ ./app/index.js 4:0-29 @ multi ./app/index.js'
Run Code Online (Sandbox Code Playgroud)
并在浏览器中:
Uncaught Error: Cannot find module "/styles/main.scss"
Run Code Online (Sandbox Code Playgroud)
我的webpack.config.js配置如下:
var HtmlWebpackPlugin = require('html-webpack-plugin');-
var HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
template: __dirname + '/app/index.html',
filename: 'index.html',
inject: 'body'
});
module.exports = {
entry: [
'./app/index.js'
],
output: {
path: __dirname + '/dist',
filename: "index_bundle.js"
},
module: {
loaders: [
{test: /\.js$/, exclude: /node_modules/, loader: "babel-loader"},{
test: /\.scss$/,
loaders: ['style', 'css', 'sass']
}
]
},
plugins: [HTMLWebpackPluginConfig]
}; …Run Code Online (Sandbox Code Playgroud) 我想在我的redux状态下更新chefs数组中的一位厨师.该数组的一个例子如下:
[
{ _id: 1, name: 'first chef' },
{ _id: 2, name: 'second chef' },
{ _id: 2, name: 'third chef' }
]
Run Code Online (Sandbox Code Playgroud)
我调用了API,然后返回更新的chef对象.我基本上在当前状态下找到相关的厨师对象,但是,当我不可更新地更新它时,我的反应组件不会重新渲染.
这是更新redux reducer中对象数组中单个对象的正确方法吗?
import _ from 'lodash';
import { ADMIN_LIST_CHEFS, ADMIN_GET_CHEF, UPDATE_CHEF_LIST } from '../actions/types';
const INITIAL_STATE = { chefs: [], chef: null };
let CHEFS = [];
let INDEX = null;
export default function (state = INITIAL_STATE, action) {
switch (action.type) {
case UPDATE_CHEF_LIST:
CHEFS = state.chefs;
INDEX = _.findIndex(CHEFS, (chef => chef._id === action.id)); …Run Code Online (Sandbox Code Playgroud) javascript ×2
reactjs ×2
arrays ×1
devise ×1
filter ×1
immutability ×1
middleware ×1
object ×1
rails-api ×1
react-redux ×1
reducers ×1
redux ×1
sass ×1
sass-loader ×1
stripe.js ×1
webpack ×1