我想知道如何在不使用 jquery 的情况下使用 VueJS 选择 DOM 中的特定元素
在我的组件中,我有一个方法函数可以做到这一点:
$(".u-loc input").focusin(function() {
$(".u-loc-icon").addClass('blue-active');
});
Run Code Online (Sandbox Code Playgroud)
唯一的问题是它是动态生成的,所以我可以有 1 或 10 个不同的,这意味着我需要为每个选择器设置一个唯一的选择器。
所以我添加了 :ref="'u-loc' + index"
这意味着我现在可以使用 $(this.$refs['u-loc' + index]);
但我不知道如何将选择器链接成如下所示:
$(this.$refs['u-loc' + index]).('input').focusin(function() {
$(this.$refs['u-loc' + index]).addClass('blue-active');
});
Run Code Online (Sandbox Code Playgroud)
问题是我需要选择元素 [input]
我是javascript的新手,我试图从一个对象数组中删除多个值.
现在我可以删除这样的一个对象
if(obj.findObjectByKey(response, 'cat_id', 171) == true) {
var catId = response.map(item => item.cat_id).indexOf(171);
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我将删除id为"171"的项目,但现在我有一个包含多个值的数组,我想删除它.
那么如何修改上面的代码让我传入一个我想从列表中删除的项目数组,例如 ['171', '172', '173, '174'];
当涉及到 laravel 批量分配时,我有点困惑。
我知道我可以使用以下方法保护字段:
protected $fillable = [
'username', 'email', 'password'
];
Run Code Online (Sandbox Code Playgroud)
并在此处受到保护:
$flight = App\Flight::create(Input:all);
or
$flight->fill(['name' => 'Flight 22']);
Run Code Online (Sandbox Code Playgroud)
但我只创建或更新这样的模型:
public function createUser(NewUserRequest $request, User $newUser)
{
$newUser->insertUser($request);
}
Run Code Online (Sandbox Code Playgroud)
insertUser看起来像这样:
public function insertUser($request)
{
$newUser = $this;
$newUser->user_type = (int) $request->input('user_type');
$newUser->username = $request->input('username');
$newUser->email = $request->input('email');
if ($request->filled('password')) {
$newUser->password = bcrypt($request->input('password'));
}
if ($request->filled('facebook_id')) {
$newUser->facebook_id = $request->input('facebook_id');
}
$newUser->save();
return $newUser;
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我总是选择要插入的字段以及应插入的数据。那么$fillable当我不使用create()orfill()方法时,我真的需要设置我的吗?
我在 Laravel 中设置了密码重置。我已通读文档https://laravel.com/docs/5.5/passwords,但我看不到是否有一个函数仅允许基于用户表中数据库中的字段为某些用户重置密码。
user_type在我的用户表中,如果设置为 2 ,我添加了该字段,user_type我不想允许为该用户发送密码重置链接
为了使用新行在 Laravel 刀片模板中输出文本,我使用以下命令:
{!! nl2br(e($prodData->text))!!}
Run Code Online (Sandbox Code Playgroud)
插入数据时,我不会对数据进行消毒,我只是将其修剪为仅允许连续两个新行,如下所示:
public function setDescriptionAttribute($description)
{
$this->attributes['description'] = preg_replace('~(\R{2})\R+~', '$1', $description);
}
Run Code Online (Sandbox Code Playgroud)
但是现在我担心{!!nl2br(e())!!}会导致 xss 注入,所以使用安全吗?
我正在使用Algolia搜索客户端PHP用于Laravel ,我想在没有Laravel Scout的情况下使用它.
现在我必须在每个需要使用Algolia的控制器中执行此操作:
$client = new \AlgoliaSearch\Client('xxx', 'xxx');
$index = $client->initIndex('index');
$index->doSomeAlgoliaFunction();
Run Code Online (Sandbox Code Playgroud)
如何将其变成服务提供商,这样我每次需要时都不需要初始化Algolia?
我有一个对象数组,如下所示:
rows [
{ id: 3,
title: "sometitle",
catid: 55,
img: "file" },
{ id: 4,
title: "sometitle",
catid: 55,
img: "file" },
{ id: 5,
title: "sometitle",
catid: 55,
img: "file" },
]
Run Code Online (Sandbox Code Playgroud)
我现在要做的是循环遍历对象数组并从每个对象中获取两个值(id和img)并将其插入到一个新的对象数组中,因此最终看起来像这样:
newArr [
{ id: 3,
img: "file" },
{ id: 4,
img: "file" },
{ id: 5,
img: "file" },
]
Run Code Online (Sandbox Code Playgroud)