我正在使用reactnavigation和redux创建一个反应原生的应用程序.
加载应用程序后,我从NavContainer收到以下警告: Warning: Failed prop type: The prop 'navigation.dispatch' is marked as required in 'CardStack', but its value is 'undefined'
当我尝试导航页面时导致错误,this.props.navigation.navigate('Station');因为nav.dispatch不是一个函数
该应用程序有一个NavContainer,我猜这是丢失的东西,因为在渲染功能中未定义调度:
import React, { Component } from 'react'
import { addNavigationHelpers } from 'react-navigation'
import AppNavigator from '../lib/navigationConfiguration'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux';
import { ActionCreators } from '../actions';
class NavContainer extends Component {
render(){
const { dispatch, navigationState} = this.props
return (
<AppNavigator
navigation={
addNavigationHelpers({
dispatch: dispatch,
state: navigationState …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails 5.1.1,对于我们想要的rspec功能测试,我们希望在运行所有功能测试之前使用预编译资产.(主要原因是因为capybara-webkit不支持javascript es6功能)
使用RAILS_ENV=test rake assets:precompilecapybara-webkit 成功预编译的资产似乎不使用预编译资产.
config/environment/test.rb看起来像这样
config.assets.prefix = "/assets_test"
config.assets.compile = true
config.serve_static_assets = true
config.assets.js_compressor = Uglifier.new(
harmony: true #es6 support
)
Run Code Online (Sandbox Code Playgroud)
我需要添加什么来测试才能使用预编译资产?
在以下简化示例中,用户使用 TextInput 更新标签状态,然后单击标题中的“保存”按钮。在提交函数中,当请求标签状态时,它返回原始值“”而不是更新后的值。
需要对导航 headerRight 按钮进行哪些更改才能解决此问题?
注意:当“保存”按钮位于渲染视图中时,一切都会按预期工作,只是当它位于标题中时则不然。
import React, {useState, useLayoutEffect} from 'react';
import { TouchableWithoutFeedback, View, Text, TextInput } from 'react-native';
export default function EditScreen({navigation}){
const [label, setLabel] = useState('');
useLayoutEffect(() => {
navigation.setOptions({
headerRight: () => (
<TouchableWithoutFeedback onPress={submit}>
<Text>Save</Text>
</TouchableWithoutFeedback>
),
});
}, [navigation]);
const submit = () => {
//label doesn't return the updated state here
const data = {label: label}
fetch(....)
}
return(
<View>
<TextInput onChangeText={(text) => setLabel(text) } value={label} />
</View>
)
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试过滤包含 Bird 类型的核心数据实体的数组数组。实体已根据带有部分和行的 UITableView 拆分为数组数组。
要搜索,我有以下方法基于这个问题NSPredicate on arrays:
func filterContentForSearchText(searchText: String) {
let resultPredicate = NSPredicate(format: "SELF[0].common_name contains[cd] %@", searchText)
self.filteredBirds = self.birds.filteredArrayUsingPredicate(resultPredicate!)
}
Run Code Online (Sandbox Code Playgroud)
然而,这会导致错误
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
Run Code Online (Sandbox Code Playgroud)
这可能是有道理的,因为数组有 27 个 (AZ, #) 元素,其中一些元素没有实体
那么,如何调整 NSPredicate 查询以考虑某些数组可能为空?