试图让JavaScript代码完成工作在netbeans与jsdoc
Trying to get JavaScript code completion to work in netbeans with jsdoc
在我的app.js中,我有以下内容:
angular.module('app').controller('userList',
['appSettings'
,function (/*@type {app.appSettings}*/appSettings) {
appSettings.<<== it shows a list here but nothing from autocomplete.js
在我的autocomplete.js中,我有以下内容(由JavaScript打印出我的服务及其成员生成):
var app={};
app.appSettings={};
app.appSettings.userFailMessages={};
app.appSettings.userFailMessages.invalidJson
="Invalid request, user sent is not valid json.";
NetBeans拒绝为我编写完整的appSettings,似乎不知道它是在autocomplete.js中定义的。也许我得到了我的js文档错误,但尝试了@var, @type和@param的组合组合没有成功。
当我输入app.appSettings.
并从autocomplete.js给我一个列表时,它的代码完成了,但我想知道如何告诉NetBeans传递给函数的参数是app.appSettings。
也许我应该让自动完成包含构造函数而不是对象字面值,因为@type暗示了某种类型而不是实例。
是NetBeans 7.3.1
接近答案,要让NetBeans使用类型,您必须定义类型。然后,为了表明传递给angular模块(或任何函数)的参数是某种类型,我使用@param jsdoc
angular模块:
angular.module('app').controller('userList'
, ['$scope','appRules','appSettings'
,/**
* @param {app.appRules} appRules
* @param {app.appSettings} appSettings
* */
function ($scope,appRules,appSettings,$timeout) {
//<== here both appRules and appSettings give suggestions
// from autocomplete
autocomplete.js(不包含在我的HTML文件中,但只是在那里的代码建议)
/*@typedef {Object} app*/
var app={};
app.appRules={};
app.appRules.userIsInRole=function (user,role){};
app.appRules.general={};
app.appRules.general.isEmpty=function (val){};
app.appRules.general.isEmail=function (val){};
app.appSettings={};
app.appSettings.userFailMessages={};
app.appSettings.userFailMessages.invalidJson
="Invalid request, user sent is not valid json.";
app.appSettings.userFailMessages.noPrivilege
="You do not have the privileges needed to change this user.";
我在控制台的一个包含我的应用程序的页面上运行了以下代码来生成autocomplete.js:
var inj;
function allServices(mod, r) {
if (!r) {
r = {};
inj = angular.element(document.querySelector('[data-ng-app]')).injector().get;
}
angular.forEach(angular.module(mod).requires, function(m) {
allServices(m, r)
});
angular.forEach(angular.module(mod)._invokeQueue, function(a) {
try {
r[a[2][0]] = inj(a[2][0]);
} catch (e) {
}
});
return r;
};
var output=[];
function addOutput(names,prop){
if(names.length===1){
output.push('var ');
}
output.push(names.join('.'));
if(typeof prop === 'object'){
output.push('={};'n');
for(thing in prop){
//TODO: no arrays or route paths
if(/[0-9'/'']/.test(thing)){
continue;
}
names.push(thing);
addOutput(names,prop[thing]);
}
}else{
output.push('=');
output.push(
(typeof prop === 'function')?
prop.toString():
JSON.stringify(prop)
);
output.push(';'n');
}
names.pop();
}
function createOutput(){
allMyServices = allServices('app');
addOutput(['app'],allMyServices);
console.log(output.join(''));
}
createOutput();
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- Javascript.getHours()工作不正常
- 为什么这在IE中的工作方式与在Firefox中不同
- 视频HTML没有'无法在Internet Explorer 11上工作
- 扩展移相器按钮类不工作
- Firebase迁移-简单的Firebase.set没有'不再工作了——旧的还是新的
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 正在尝试使用if和else添加类,但无法正常工作
- Jquery FadeIn FadeOut 只工作一次
- Foreach无法在Typescript中工作
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- JS可以在Chrome中工作,但不能在Firefox中工作
- NetBeans调试突然停止工作
- 试图让JavaScript代码完成工作在netbeans与jsdoc
- 为什么我的Netbeans 8 javascript自动完成不工作在我的AngularJS项目