PHPStorm IDE中效率低下的jQuery使用警告 [英] Inefficient jQuery usage warnings in PHPStorm IDE

查看:221
本文介绍了PHPStorm IDE中效率低下的jQuery使用警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级了我的PHPStorm IDE版本,现在它警告我有关jQuery使用效率低下的问题.

I recently upgraded my version of PHPStorm IDE and it now warns me about inefficient jQuery usage.

例如:

var property_single_location = $("#property [data-role='content'] .container");

提示此警告:

检查是否有效使用了jQuery选择器.这表明 拆分以ID选择器和 警告可能会被缓存的重复的选择器.

Checks that jQuery selectors are used in an efficient way. It suggests to split descendant selectors which are prefaced with ID selector and warns about duplicated selectors which could be cached.

所以我的问题是:

为什么这种效率低下?做上述选择器的有效方法是什么?

Why is this inefficient and what is the efficient way to do the above selector?

我猜在:

var property_single_location = $("#property").find("[data-role='content']").find(".container");

这是正确的方法吗?

推荐答案

我今天遇到了同样的问题,由于 此处 > .

I had the same question today and was able to find a solution thanks to Scott Kosman here.

基本上,答案是单独选择ID,然后对以下任何内容使用.find(...).因此,以您的示例为例:

Basically the answer is to select IDs individually and then use .find(...) for anything below. So taking your example:

$("#property [data-role='content'] .container");

对此进行更改会使PhpStorm感到高兴,并且显然可以两倍快:

Changing it to this makes PhpStorm happy and can evidently be more than twice as fast:

$("#property").find("[data-role='content'] .container");

这篇关于PHPStorm IDE中效率低下的jQuery使用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆