所以我尝试使用 React Native 和 onEndEditing 构建表单验证。
所以我的 React Native 代码如下所示:
<TextInput onSubmitEditing={value => console.log(value)} />
Run Code Online (Sandbox Code Playgroud)
当用户停止编辑时,它应该记录该值。但我得到的不是日志:
{"_dispatchInstances": {"_debugHookTypes": null, "_debugID": 1400, "_debugIsCurrentlyTiming": false,
"_debugNeedsRemount": false, "_debugOwner": {"_debugHookTypes": [Array], "_debugID": 1394,
"_debugIsCurrentlyTiming": false, "_debugNeedsRemount": false, "_debugOwner": [FiberNode], "_debugSource":
[Object], "actualDuration": 0, "actualStartTime": 5771, "alternate": [FiberNode], "child": [FiberNode],
"childExpirationTime": 0, "dependencies": null, "effectTag": 517, "elementType": [Function
InternalTextInput], "expirationTime": 0, "firstEffect": [Circular], "index": 0, "key": null, "lastEffect":
[FiberNode], "memoizedProps": [Object], "memoizedState": [Object], "mode": 8, "nextEffect": null,
"pendingProps": [Object], "ref": null, "return": [FiberNode], "selfBaseDuration": …Run Code Online (Sandbox Code Playgroud) 所以,我有这个错误。我使用名为 的第三方包PhoneNumber。现在,当我想序列化我的数据时,我收到此错误:Object of type PhoneNumber is not JSON serializable
我可以猜测问题是什么,但不知道如何解决它:/以前有人遇到过这个/类似的问题吗?:)
serializer.py
from rest_framework import serializers
from phonenumber_field.serializerfields import PhoneNumberField
from user.models import Account
class RegistrationSerializer(serializers.ModelSerializer):
password2 = serializers.CharField(style={'input_type': 'password'}, write_only=True)
# country = serializers.ChoiceField(
# choices=['US', 'DE', 'FR', 'CH', 'AT', 'GB', 'SE', 'NO', 'FI', 'DK', 'IT', 'ES', 'PT']
# )
phone_number = PhoneNumberField()
class Meta:
model = Account
fields = ['phone_number', 'username', 'first_name', 'country', 'email', 'password', 'password2']
extra_kwargs = {
'password': {'write_only': True},
}
def save(self):
account …Run Code Online (Sandbox Code Playgroud) 我现在面临的问题是,当表情符号的肤色与黄色不同时,Javascript 会将其分割为不同的字符,而不是一个字符。
\n当我有这样的表情符号时,就没有问题了,我得到了我想要的结果。
\nlet strs = [...""]\n\nconsole.log(strs)\nconsole.log(strs.length)Run Code Online (Sandbox Code Playgroud)\r\n但如果我有这样的表情符号,就会出现问题,因为 javascript 不允许我对这个表情符号使用 [...] 运算符:
\nlet strs = [...""]\n\nconsole.log(strs)\nconsole.log(strs.length)Run Code Online (Sandbox Code Playgroud)\r\n我如何告诉 Javascript 这些只是一个长度为 1 的表情符号,而不是像本示例中那样的两个或多个表情符号:
\nlet strs = [..."\xe2\x80\x8d\xe2\x9d\xa4\xef\xb8\x8f\xe2\x80\x8d\xe2\x80\x8d"]\n\nconsole.log(strs)\nconsole.log(strs.length)Run Code Online (Sandbox Code Playgroud)\r\n