我有一个reducer,为了计算新的状态,我需要来自动作的数据,以及来自该reducer未管理的部分状态的数据.具体来说,在减速机中我将在下面显示,我需要访问该accountDetails.stateOfResidenceId
字段.
initialState.js:
export default {
accountDetails: {
stateOfResidenceId: '',
accountType: '',
accountNumber: '',
product: ''
},
forms: {
blueprints: [
]
}
};
Run Code Online (Sandbox Code Playgroud)
formsReducer.js:
import * as types from '../constants/actionTypes';
import objectAssign from 'object-assign';
import initialState from './initialState';
import formsHelper from '../utils/FormsHelper';
export default function formsReducer(state = initialState.forms, action) {
switch (action.type) {
case types.UPDATE_PRODUCT: {
//I NEED accountDetails.stateOfResidenceId HERE
console.log(state);
const formBlueprints = formsHelper.getFormsByProductId(action.product.id);
return objectAssign({}, state, {blueprints: formBlueprints});
}
default:
return state;
}
}
Run Code Online (Sandbox Code Playgroud)
index.js(root reducer): …
我正在尝试使用Gradle运行一个非常简单的项目,并在使用时遇到以下错误gradlew run command
:
could not find or load main class 'hello.HelloWorld'
这是我的文件结构:
SpringTest
-src
-hello
-HelloWorld.java
-Greeter.java
-build
-libs
-tmp
-gradle
-wrapper
-build.gradle
-gradlew
-gradlew.bat
Run Code Online (Sandbox Code Playgroud)
我排除了libs和tmp文件夹的内容,因为我认为这不是这个问题的相关信息,但如果需要我可以添加它.
这是我的build.gradle文件:
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
mainClassName = 'hello/HelloWorld'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "joda-time:joda-time:2.2"
}
jar {
baseName = "gs-gradle"
version = "0.1.0"
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
Run Code Online (Sandbox Code Playgroud)
有关如何解决此问题的任何想法?我已经为mainClassName属性尝试了各种各样的东西,但似乎没有任何效果.
我想知道,我如何在Selectize.js输入中获得当前所选项目的值?我已经检查了文档并搜索了与Stackoverflow相关的所有selectize.js,但没有发现任何可能的例子.有任何想法吗?这是我认为基于文档的工作,但反而给了我Undefined is not a function
错误.
请注意代码的最底部,我在哪里使用select.on('change'
; 这(除了其他API方法)是我尝试过的.改变是完美的,但不幸的是没有别的.
var select = $('#searchTextbox').selectize({
maxItems: 1, //Max items selectable in the textbox
maxOptions: 30, //Max options to render at once in the dropdown
searchField: ['text'], //Fields the autocomplete can search through. Example of another searchable field could be 'value'
openOnFocus: true,
highlight: true,
scrollDuration: 60, //currently does nothing; should say how many MS the dropdown and drop up animations take
create: false, //Whether or not the user is allowed …
Run Code Online (Sandbox Code Playgroud) 所以我有这个使用redux thunk
中间件的Redux动作创建者:
accountDetailsActions.js:
export function updateProduct(product) {
return (dispatch, getState) => {
const { accountDetails } = getState();
dispatch({
type: types.UPDATE_PRODUCT,
stateOfResidence: accountDetails.stateOfResidence,
product,
});
};
}
Run Code Online (Sandbox Code Playgroud)
我该如何测试?我正在使用该chai
软件包进行测试.我在网上找到了一些资源,但不确定如何继续.这是我到目前为止的测试:
accountDetailsReducer.test.js:
describe('types.UPDATE_PRODUCT', () => {
it('should update product when passed a product object', () => {
//arrange
const initialState = {
product: {}
};
const product = {
id: 1,
accountTypeId: 1,
officeRangeId: 1,
additionalInfo: "",
enabled: true
};
const action = actions.updateProduct(product);
const store = mockStore({courses: []}, …
Run Code Online (Sandbox Code Playgroud) 所以在我的应用程序中,用户可以选择将文件上传到<input type = "file" id = "my-file">
(HTML 5文件输入).我随后可以使用以下Javascript获取此文件:
var files = $("#my-file").files;
var file = files[0];
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式使用这个var file
作为data
在<object>
标签?下面是一个对象标记的示例,其中通过点击URL并联系服务器来抓取PDF.
<object data="data/test.pdf" /*<-- I want the var file here */ type="application/pdf" width="300" height="200">
</object>
Run Code Online (Sandbox Code Playgroud)
我怎么能做到这一点?请注意,我必须支持Internet Explorer 11.
更新:
我尝试过最终以失败告终的事情.我使用FileReader将PDF转换为数据uri,然后data
在<object>
标记的属性中使用它,这在Chrome中完全呈现,但在Internet Explorer中根本不呈现.
var files = $(e.currentTarget.files);
file = files[0];
var reader = new FileReader();
reader.onloadend = function() {
var data = reader.result;
console.log(data);
$("#content").prepend('<object id="objPdf" data="'+data+'" type="application/pdf"></object>');
};
reader.readAsDataURL(file);
Run Code Online (Sandbox Code Playgroud)
读者数据出现的地方如下:
data:application/pdf;base64,JVBERi0xLjQKJe...
Run Code Online (Sandbox Code Playgroud)
尝试运行我的项目,收到以下错误(You may need an appropriate loader to handle this file type.
)为.eot
,.woff
,.ttf
,和.svg
文件:
ERROR in ./src/styles/fonts/nm/icons/nm-icons.svg?aaf8685e87a6901c76c52d0018389547
Module parse failed: C:\BaseProject\src\styles\fonts\nm\icons\nm-icons.svg?aaf8685e87a6901c76c52d0018389547 Unexpected t
oken (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:0)
at Parser.pp$4.raise (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15)
at Parser.pp.unexpected (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10)
at Parser.pp$3.parseExprAtom (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:1822:12)
at Parser.pp$3.parseExprSubscripts (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:1715:21)
at Parser.pp$3.parseMaybeUnary (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:1692:19)
at Parser.pp$3.parseExprOps (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:1637:21)
at Parser.pp$3.parseMaybeConditional (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:1620:21)
at Parser.pp$3.parseMaybeAssign (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:1597:21)
at Parser.pp$3.parseExpression (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:1573:21)
at Parser.pp$1.parseStatement (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:727:47)
at Parser.pp$1.parseTopLevel (C:\BaseProject\node_modules\webpack\node_modules\acorn\dist\acorn.js:638:25) …
Run Code Online (Sandbox Code Playgroud) 所以我有一个React.js组件,我想循环遍历我导入的对象以向其添加HTML选项.这是我尝试过的,既丑陋又无效:
import React from 'react';
import AccountTypes from '../data/AccountType';
const AccountTypeSelect = (props) => {
return (
<select id={props.id} className = {props.classString} style={props.styleObject}>
<option value="nothingSelected" defaultValue>--Select--</option>
{
$.each(AccountTypes, function(index) {
<option val={this.id}>this.name</option>
})
}
</select>
);
};
export default AccountTypeSelect;
Run Code Online (Sandbox Code Playgroud)
我从上面的代码中在控制台中收到此错误:
invariant.js?4599:38 - Uncaught Invariant Violation:对象无效作为React子对象(找到:具有键{id,name,enabled,additionalInfo}的对象).如果您要渲染子集合,请使用数组,或使用React附加组件中的createFragment(object)包装对象.检查渲染方法AccountTypeSelect
.
我真的需要将每个对象转换为数组或使用createFragment包装它来使用它吗?这种情况的最佳做法是什么?
1)
所以我试图让我的导航栏都设置好引导程序,不幸的是底部似乎有一条1px线,我似乎无法摆脱它.有谁能建议任何解决方案?
2)
此外,有没有办法在导航栏的每一侧获得间隙,但仅当视口高于768px?我可以通过移动开头标签的外部来实现这种效果,但就像我说我希望导航栏在移动设备上查看网站时向后移动.
这是我的代码: http ://pastebin.com/zHP09rNu
谢谢.
在我的configureStore.dev.js文件中使用此代码,我Uncaught TypeError: getState is not a function
在添加时得到了一个applyMiddleware(reduxImmutableStateInvariant)
.当我删除这个添加的中间件时,我的项目运行正常.添加此中间件的正确方法是什么?这是完整的文件:
import {createStore, compose, applyMiddleware} from 'redux';
import rootReducer from '../reducers';
import reduxImmutableStateInvariant from 'redux-immutable-state-invariant';
export default function configureStore(initialState) {
const store = createStore(rootReducer, initialState, compose(
// Add other middleware on this line...
applyMiddleware(reduxImmutableStateInvariant),
window.devToolsExtension ? window.devToolsExtension() : f => f // add support for Redux dev tools
)
);
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextReducer = require('../reducers').default; // …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Spring 4设置Hibernate 4,并且我遇到了一些配置它的问题.具体来说,在我的servlet-context.xml
文件中,我按照指南并将以下代码块添加到此文件中:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>/WEB-INF/hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Run Code Online (Sandbox Code Playgroud)
这两个都显示以下错误: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'bean'
会话工厂bean也显示此错误: Cannot locate BeanDefintionParser for element [bean]
这是我的整个`servlet-context.xml'文件(为了简洁起见,不包括那两个代码块,但请注意它们实际上在文件中):
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">
<!-- DispatcherServlet Context: …
Run Code Online (Sandbox Code Playgroud) javascript ×6
reactjs ×3
redux ×3
java ×2
spring ×2
babeljs ×1
base64 ×1
build.gradle ×1
chai ×1
css ×1
data-uri ×1
gradle ×1
hibernate ×1
html ×1
html5 ×1
jquery ×1
jsx ×1
middleware ×1
npm ×1
object-tag ×1
pdf ×1
react-jsx ×1
selectize.js ×1
servlets ×1
spring-mvc ×1
webpack ×1