【发布时间】:2020-07-06 22:24:36
【问题描述】:
我正在使用 laravel 创建一个可以拥有多个项目的用户集合。我想将该集合传递给 javascript 对象,以便我可以检查用户是否具有特定对象。
我使用以下行来获取集合的内容并将其传递给页面:
let items = {!! $user->items->toJson() !!};
这给了我以下结构:
Array ->
0: Object {brand: "brand1", reference: "23423", description: "Item 1 description text"}
1: Object {brand: "brand2", reference: "22344", description: "Item 6 description text"}
2: Object {brand: "brand1", reference: "23239", description: "Item 24 description text"}
3: Object {brand: "brand5", reference: "24908", description: "Item 106 description text"}
4: Object {brand: "brand3", reference: "14545", description: "Item 7 description text"}
如何检查引用“14545”(例如)是否是数组的一部分?
感谢您的帮助。
亚当
【问题讨论】:
标签: javascript arrays json laravel