小编Alh*_*nIQ的帖子

带有通配符的Laravel验证器

我想制作一个laravel验证器来验证数组内部未命名数组(0,1,2,3)内的字段

所以我的阵列就像

array [ //the form data
  "items" => array:2 [ //the main array i want to validate
    0 => array:2 [ // the inner array that i want to validate its data
      "id" => "1"
      "quantity" => "1000"
     ]
    1 => array:2 [
     "id" => "1"
     "quantity" => "1000"
     ]
  // other fields of the form,
  ]

]
Run Code Online (Sandbox Code Playgroud)

所以我想要的是类似的东西

  $validator = Validator::make($request->all(), [
     'items.*.id' => 'required' //notice the star *
  ]);
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5 laravel-5.1

6
推荐指数
1
解决办法
3916
查看次数

在JQuery中选择json数据

我有一个ajax表单,响应数据是这个json

[{"runtime":"142 min" , "title":"blabla"}]
Run Code Online (Sandbox Code Playgroud)

但是当我从chrome开发人员工具中看到它时,就像这样

[Object]
0: Object
runtime: "142 min"
title: "blabla"
__proto__: Object
length: 1
__proto__: Array[0]
Run Code Online (Sandbox Code Playgroud)

如果我想将其中一个键设置为var应该怎么做

我试过var x = data.runtime ;但它不起作用

我试过var x = data.0.runtime ; ,它会导致语法错误

arrays ajax jquery json

0
推荐指数
1
解决办法
37
查看次数

标签 统计

ajax ×1

arrays ×1

jquery ×1

json ×1

laravel ×1

laravel-5 ×1

laravel-5.1 ×1

php ×1