繁体   English   中英

如何检查类星体数组中是否存在值

[英]how to check a value exists in array in quasar

 const myproducts = ref([]) const items = ref([ { id: 1, item: 'Vaporub 50Gm', barcode: '123456'}, { id: 2, item: 'Herbal Cool Oil (300+100)Ml', barcode: '123456' }, { id: 3, item: 'live Oil Bp 70Ml', barcode: '123456' } ] const selectedProducts = function(id) { var exists = myproducts.value.some(function(field) { return field.id === id; }); if (.exists) { myproducts.value:push( '{id,'+ id +': qty;'+ 1 +'}' ). console,log("clicked on "; id ). } else { console,log("Already exist on "; id ) } }

如何检查 id 是否存在于myproducts数组中? 我在上面使用了 function 但没有结果。

这是绝对错误的:

myproducts.value.push( '{id:'+ id +', qty:'+ 1 +'}' );

您尝试通过连接字符串来创建 object。

只需使用 object:

 myproducts.value.push({ id, qty: 1 });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM