嘿我在vue.js写一段代码。我有复选框的问题。我有两个,他们与我的后端连接。它们看起来像这样:
<b-form-checkbox
v-model="selectedUser.institutionPersonRelations[0].communicationBlocked" @change="editBlockOfCommunication({institutionId:selectedUser.institutionPersonRelations[0].id, profileId:selectedUser.id})">
</b-form-checkbox>
<b-form-checkbox v-model="selectedUser.institutionPersonRelations[0].uploadBlocked" @change="editUploadBlock({institutionId:selectedUser.institutionPersonRelations[0].id, profileId:selectedUser.id})" :disabled="selectedUser.institutionPersonRelations[0].communicationBlocked == true">
</b-form-checkbox>
一切正常,直到我选中第二个复选框,然后选中第一个复选框,然后取消选中第一个复选框。首先在数据库中更改值X和Y.数据库中的第二个更改值Y.在这种情况下数据库正确更新但第二个复选框即使设置为false仍然被检查,我需要重新加载页面来更新它。
我在php中的后端在复选框上点击更改事件
public function editBlockOfCommunicationForProfile(int $institutionPersonId, int $profileId): void
{
$entityManager = $this->ormGateway->getEntityManager();
$profile = $entityManager->find(ProfileDto::class, $profileId);
if ($profile !== null) {
$institutionProfile = $profile->getInstitutionPersonRelationWithGivenId($institutionPersonId);
if ($institutionProfile !== null) {
if (!$institutionProfile->getDeactivated()) {
if ($institutionProfile->getCommunicationBlocked() === false) {
$institutionProfile->setCommunicationBlocked(true);
$institutionProfile->setUploadBlocked(true);
}
else {
$institutionProfile->setCommunicationBlocked(false);
$institutionProfile->setUploadBlocked(false);
}
}
}
}
$entityManager->flush();
}
/**
* @param int $institutionPersonId
* @param int $profileId
*/
public function editUploadBlockForProfile(int $institutionPersonId, int $profileId): void
{
$entityManager = $this->ormGateway->getEntityManager();
$profile = $entityManager->find(ProfileDto::class, $profileId);
if ($profile !== null) {
$institutionProfile = $profile->getInstitutionPersonRelationWithGivenId($institutionPersonId);
if ($institutionProfile !== null) {
if (!$institutionProfile->getDeactivated()) {
if($institutionProfile->getCommunicationBlocked() === false) {
if ($institutionProfile->getUploadBlocked() === false) {
$institutionProfile->setUploadBlocked(true);
} else {
$institutionProfile->setUploadBlocked(false);
}
}
}
}
}
$entityManager->flush();
}