我正在将Vue.js与JavaScript结合使用。
我有一个名为let a = [{id: 1, selected: false, key: "plan"}];
let b = [{id: 1, selected: true, key: "plan", "text": "aaaa"}, {id: 2, selected: true}];
let bigger = a.length > b.length ? a : b;
let shorter = a.length < b.length ? a : b;
console.log(bigger.map(x => ({...x, ...shorter.find(y => y.id === x.id)})))
的对象数组,每个对象都有一个名为- name: This starts the MySQL Database in the host
hosts: dbserver
connection: ssh
become: yes
become_method: sudo
tasks:
- name: Start the DB in host
become: yes
become_user: root
service:
name: mysql
state: started
的{{1}}。我只想过滤带有条形码的产品,例如products
,所以我执行了此功能:
property
一切正常,但是如果smallest_unit_barcode
,我会收到此错误:
value
在过滤产品数组时如何忽略if (value != '') {
var results = this.products.filter(obj=>obj.smallest_unit_barcode.includes(value));
var results = results.slice(Math.max(results.length - 20, 0))
this.pos_quick_lunch = results;
}
值?
答案 0 :(得分:4)
在尝试访问媒体资源之前,先与null
进行比较:
obj => obj.smallest_unit_barcode !== null && obj.smallest_unit_barcode.includes(value)
由于&&
为short circuiting,因此如果左操作数的值为false,则不会计算右操作数。