我想通过传递字符串名称来获取类的属性。我怎样才能做到这一点?
class A {
String fName ='Hello';
}
main() {
A a = A();
String var1='fName'; // name of property of A class
print (a.fName); // it is working fine
print (a.$var1); // it is giving error that no getter in A class. but I want to pass var1 and automatically get the associate property
}
Run Code Online (Sandbox Code Playgroud) 我想通过 GrahQL 和 React 保存一个大表单。我将所有表单值都放在一个变量名中:formValue 有没有办法将“formValue”传递给这样的查询?
const [toSaveUserProfile] = useMutation(SAVE_USER_PROFILE)
toSaveUserProfile({ variables: formValue })
const SAVE_USER_PROFILE = gql`
mutation saveUserProfile($profileId: String!) {
updateProfile(profile: { formValue }) {
id
}
}
`
Run Code Online (Sandbox Code Playgroud)
或者我应该一一传递所有字段并像这样定义它们的类型?
const [toSaveUserProfile] = useMutation(SAVE_USER_PROFILE)
toSaveUserProfile({ variables: formValue })
const SAVE_USER_PROFILE = gql`
mutation saveUserProfile($id: String!, $firstName: String, $lastName: String, $age: Int, ......) {
updateProfile(profile: { id: $id, firstName: $firstName, lastName: $lastName, age:$age, ......}) {
id
}
}
`
Run Code Online (Sandbox Code Playgroud)
模式看起来像这样
updateProfile(profile: ProfileDTOInput!): ProfileDTO
type ProfileDTO {
address: String …Run Code Online (Sandbox Code Playgroud)