javascript 如何让 jQuery 代码完成在 Sublime Text 2 中工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18005219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get jQuery code completion to work in Sublime Text 2?
提问by AngryHacker
I am doing some light jQuery based Javascript programming with Sublime Text 2. Is there such a thing as code completion for jQuery? I've installed SublimeCodeIntel, but getting nothing.
我正在使用 Sublime Text 2 进行一些基于 jQuery 的轻量级 Javascript 编程。是否有 jQuery 代码完成之类的东西?我已经安装了 SublimeCodeIntel,但什么也没得到。
For instance, consider the following:
例如,请考虑以下事项:
<div id="container">hello</div>
<script type="text/javascript">
function doStuff() {
$('#container').html('change it');
}
</script>
When I type $('#container').
I would expect a popup with things like html
, val
, etc... to popup. Has anyone gotten jQuery intellisense to work at all?
当我型$('#container').
我希望的东西就像一个弹出html
,val
等...来弹出。有没有人让 jQuery 智能感知工作?
P.S. To be sure, I am not trying to get snippets working, but rather code completion.
PS 可以肯定的是,我不是要让代码片段工作,而是要完成代码。
回答by Rajesh Paul
Try package installerin sublime
在 sublime 中尝试包安装程序
search for jquery
and install.
搜索jquery
并安装。
回答by MattDMo
SublimeCodeIntel should work just fine with jQuery, you just need to tell it where to find it. Check out the docs on configuring search paths- basically, you create a ~/.codeintel/config
file, and put something like
SublimeCodeIntel 应该与 jQuery 一起工作得很好,你只需要告诉它在哪里可以找到它。查看有关配置搜索路径的文档- 基本上,您创建一个~/.codeintel/config
文件,然后放置类似
{
"JavaScript": {
"javascriptExtraPaths": ["/path/to/jquery.not-minified.js"]
}
}
in it. Remember to notuse the minified version of jQuery, as some of the variable names can be changed (I think, don't hold me to it for v2). You also don't have the inline documentation. This file can also be created as /path/to/project_root/.codeintel/config
if you're using different versions, different plugins, etc. Remember that SublimeCodeIntel can take a little while to index everything, so be patient the first time it runs. I've found it helpful to restart Sublime after indexing is done, just so everything is freshly loaded.
在里面。请记住不要使用 jQuery 的缩小版本,因为某些变量名称可以更改(我认为,对于 v2,不要强迫我这样做)。您也没有内联文档。这个文件也可以像/path/to/project_root/.codeintel/config
你使用不同的版本、不同的插件等一样创建。请记住,SublimeCodeIntel 可能需要一些时间来索引所有内容,所以第一次运行时请耐心等待。我发现在索引完成后重新启动 Sublime 很有帮助,这样一切都是新加载的。
回答by Srikanth AD
This jQuery package for Sublime text might help https://github.com/mrmartineau/Jquery
这个用于 Sublime 文本的 jQuery 包可能会有所帮助 https://github.com/mrmartineau/Jquery
回答by Andy G
If you have installed a jQuery syntax-file (there is one available from the link provided by Srikanth AD) then my AndyJS2add-in is available via PackageControl.
如果你已经安装了一个jQuery语法文件(有一个可从SRIKANTH AD提供的链接),然后我AndyJS2插件通过提供PackageControl。
AndyJS2 provides completions for both JavaScript and jQuery - use the syntax options by clicking the bottom-right of the ST window to switch between JavaScript and jQuery.
AndyJS2 为 JavaScript 和 jQuery 提供补全 - 通过单击 ST 窗口的右下角使用语法选项在 JavaScript 和 jQuery 之间切换。
I doubt that it would work well, though, in parallel with SublimeCodeIntel. You can disable this Package, without having to uninstall it, from the Preferences menu, Package Control
不过,我怀疑它是否能与 SublimeCodeIntel 并行运行。你可以禁用这个包,而不必卸载它,从首选项菜单包控制