这是我的验证架构:
const validationSchema = Yup.object().shape({
person: Yup.object().shape({
name: Yup.string().required('Field is required'),
surname: Yup.string().required('Field is required'),
middleName: Yup.string().required('Field is required'),
email: Yup.string()
.email('Wrong e-mail format')
.required('Field is required')
}),
company: Yup.object().shape({
name: Yup.string().required('Field is required'),
address: Yup.string().required('Field is required'),
email: Yup.string()
.email('Wrong e-mail format')
.required('Field is required')
})
});
Run Code Online (Sandbox Code Playgroud)
而且 React State 中有两个变量:isPerson和isCompany。如何使验证工作条件,例如,如果isPerson是真的,那么person在validationSchema需要进行验证?
我在 React Native 项目中使用 Eslint,在这段代码中:
export default class AuthLoadingScreen extends React.Component {
constructor() {
super();
this.bootstrapAsync();
}
bootstrapAsync = async () => {
const userToken = await AsyncStorage.getItem('userToken');
this.props.navigation.navigate(userToken ? 'App' : 'Auth');
};
render() {
return (
<View style={styles.container}>
<ActivityIndicator />
<StatusBar barStyle="default" />
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
Eslint 给出警告:“必须使用解构道具赋值”。我试图将分配更改为
const navigation = this.props;
navigation.navigate(userToken ? 'App' : 'Auth');
Run Code Online (Sandbox Code Playgroud)
但它给出了一个错误:“未定义不是一个对象”
编辑: 将构造函数更改为:
constructor(props) {
super(props);
this.bootstrapAsync(props);
}
Run Code Online (Sandbox Code Playgroud)
现在代码运行没有错误
有两个数组:
[
{"id": "5c5030b9a1ccb11fe8c321f4", "quantity": 1},
{"id": "344430b94t4t34rwefewfdff", "quantity": 5},
{"id": "342343343t4t34rwefewfd53", "quantity": 3}
]
Run Code Online (Sandbox Code Playgroud)
和
[
{"id": "5c5030b9a1ccb11fe8c321f4", "quantity": 2},
{"id": "344430b94t4t34rwefewfdff", "quantity": 1}
]
Run Code Online (Sandbox Code Playgroud)
如何将它们合并为一个求和量?
[
{"id": "5c5030b9a1ccb11fe8c321f4", "quantity": 3},
{"id": "344430b94t4t34rwefewfdff", "quantity": 6},
{"id": "342343343t4t34rwefewfd53", "quantity": 3}
]
Run Code Online (Sandbox Code Playgroud)
其中之一有时可能是空的
我想在 iOS 上的 Xamarin 中隐藏后退按钮的文本,我试过:
<Style TargetType="NavigationPage">
<Setter Property="BackButtonTitle" Value="" />
</Style>
Run Code Online (Sandbox Code Playgroud)
和这个代码:
<Style TargetType="ContentPage">
<Setter Property="NavigationPage.BackButtonTitle" Value="" />
</Style>
Run Code Online (Sandbox Code Playgroud)
但文字仍然出现
解决了:
iOS渲染器:
[assembly: ExportRenderer(typeof(ContentPage), typeof(BackButtonPag))]
[assembly: ExportRenderer(typeof(NavigationPage), typeof(BackButtonNav))]
public class BackButtonPag : PageRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
if (NavigationController != null)
NavigationController.TopViewController.NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
}
}
public class BackButtonNav : NavigationRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
NavigationBar.TopItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
}
}
Run Code Online (Sandbox Code Playgroud)
也添加这个
NavigationPage.BackButtonTitle = ""
Run Code Online (Sandbox Code Playgroud)
到 …
我的目标是在我的 React Native 应用程序中制作一个带有 3D 模型的页面,我发现最简单的方法是使用expo-threelibrary。但它需要Expo,所以在我的情况下这不是一个选择。我还能用什么来做到这一点?任何帮助表示赞赏。
数组看起来像
products = [
{
"id": "5c94aa7b7a37631ce2a97a72",
"material": "5c9485d37804946bc487ce59",
},
{
"id": "5c94aa7b7a37631ce2a97a72",
"material": "5c94862a7804946bc487ce5e",
},
{
"id": "5c94aa7b7a37631ce2a97a72",
"material": "5c9486397804946bc487ce61",
},
{
"id": "5c94a0a87a37631ce2a979de",
"material": "5c9485d37804946bc487ce59",
},
{
"id": "5c94a0a87a37631ce2a979de",
"material": "5c94862a7804946bc487ce5e",
},
{
"id": "5c94a0a87a37631ce2a979de",
"material": "5c9486397804946bc487ce61",
}
]
Run Code Online (Sandbox Code Playgroud)
当我尝试使用id="5c94aa7b7a37631ce2a97a72"和仅删除一项material="5c9485d37804946bc487ce59"
我使用过滤功能
filtered = products.filter(x => x.id !== id && x.material !== material);
Run Code Online (Sandbox Code Playgroud)
它将删除所有具有这些ID和材料的产品。在此功能中设置条件的正确方法是什么?