- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 vuelidate 中遇到导致无限循环的问题。这是我的项目的简要过程。我有一个 datatable
,我使用 Firebase OnSnapShot
函数对表格进行分页。该表具有操作列,单击时将显示模态。当我更新来自表的值时,vuelidate isUnique
函数会触发一个无限循环。
P.S 我在查看模式之前分离监听器
无限循环的输出:
这是我加载数据表
的函数:
async loadData(firebasePagination) {
// query reference for the messages we want
let ref = firebasePagination.db;
// single query to get startAt snapshot
ref.orderBy(firebasePagination.orderColumn, 'asc')
.limit(this.pagination.rowsPerPage).get()
.then((snapshots) => {
// save startAt snapshot
firebasePagination.start = snapshots.docs[snapshots.docs.length - 1]
// create listener using endAt snapshot (starting boundary)
let listener = ref.orderBy(firebasePagination.orderColumn)
.endAt(firebasePagination.start)
.onSnapshot((datas) => {
if(!datas.empty){
datas.docs.forEach((data, index) => {
//remove duplicates
console.log("here")
firebasePagination.data = firebasePagination.data.filter(x => x.id !== data.id)
//push to the data
firebasePagination.data.push(Object.assign({id : data.id },data.data()))
if(datas.docs.length-1 === index){
//sort
firebasePagination.data.sort((a, b) => (a[firebasePagination.orderColumn] > b[firebasePagination.orderColumn]) ? 1 : -1)
//get the current data
firebasePagination.currentData = this.getCurrentData(firebasePagination)
}
})
}
})
// push listener
firebasePagination.listeners.push(listener)
})
return firebasePagination;
}
这是我点击 Action 时的功能(模态):
switch(items.action) {
case 'edit':
//detaching listener
this.firebasePagination.listeners.forEach(d => {
d()
});
items.data.isEdit = true;
this.clickEdit(items.data);
break;
}
}
这是我的 isUnique
函数:
validations: {
department: {
name: {
required,
async isUnique(value){
if(value.trim() === ''){
return false;
}
if(strictCompareStrings(this.departmentName, value)){
this.departmentError.isActive = true;
this.departmentError.isValid = true;
return true;
}
const result = await checkIfUnique(DB_DEPARTMENTS, {nameToLower : this.department.name.toLowerCase()});
console.log("GOES HERE")
if(!result.isValid){
result.errorMessage = result.isActive ?
'Department already exists.' : 'Department has been archived.';
}
this.departmentError = Object.assign({}, result);
return this.departmentError.isValid;
}
}
}
}
这是我的 checkUnique 函数:
export const checkIfUnique = (db, nameObj, isTrim = true) => {
return new Promise(resolve => {
const nameObjKey = Object.keys(nameObj)[0];
const name = isTrim ? nameObj[nameObjKey].replace(/\s+/g,' ').trim().toLowerCase() : nameObj[nameObjKey].trim();
db().where(nameObjKey, '==', name).get()
.then((doc) => {
let result = {isActive: false, isValid: true, errorMessage: ''};
if(!doc.empty){
result.isActive = doc.docs[0].data().isActive;
result.isValid = false;
}
resolve(result);
})
});
};
最佳答案
查看另一个使用来自 here 的 isUnique
的示例并考虑到您可能必须从 isUnique
本身返回 Promise
本身。
isUnique(value) {
if (value === '') return true
return new Promise((resolve, reject) => {
yourQueryMethod(`....`)
.then(result => resolve(result))
.catch(e => reject(false));
})
}
但话又说回来,我们仍然有一个关于 Infinite loop when using a promise-based validate #350 的悬而未决的问题.
关于javascript - Vuelidate isUnique 导致无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58551915/
我在 vuelidate 中遇到导致无限循环的问题。这是我的项目的简要过程。我有一个 datatable,我使用 Firebase OnSnapShot 函数对表格进行分页。该表具有操作列,单击时将显
蛋糕 php 验证“isUnique”在编辑时出现错误 var $validate = array( 'name' => array( 'notempty' => array
我不明白 Mongoose 模式中 unique 和 required 等字段的用途。对于unique,您似乎必须编写自己的方法来查询 MongoDB 以查看该值是否已存在。我想对于“必需”Mongo
我的 BlockedTable.php 中有以下规则 public function buildRules(RulesChecker $rules) { $rules->add($rules-
我有一个带有主键的表,但我想约束另外两个列,以便保证两者的组合始终是唯一的。 (一个愚蠢的例子:在 BOOKS 表中,IBAN 列是主键,但 Title 和 Author 列的组合也应该始终是唯一的。
我是一名优秀的程序员,十分优秀!