Phpstorm 不断告诉我有一个 undefined variable input.connectto
HTML: ojit_代码
JS:
$(document).on('click', '.b-showColorinList', function() {
cm.showColorInList( $(this) );
});
还有:
/**
* Uses ajax to get other color in list view
* @param {object} inputObj
*/
cm.showColorInList = function(inputObj) {
"use strict";
var input = inputObj.data(),
parent = $("#"+input.connectto),
othervalue = input.othervalue;
我知道我可以忽略 jshint 中的一行,但是有什么方法可以使用 jsdoc 使其正确,例如将 <div class="b-showColorinList" data-connectto="123456" data-othervalue="Lorem Ipsum">...
定义为对象
最佳答案
据JSDoc docs正确的方法应该使用 @typedef
定义实际的对象结构(如果稍后在其他地方重用则特别有用)和 @type
声明特定变量的类型:
/**
* @typedef {Object} MyInputData
* @property {string} connectto
* @property {string} othervalue
*/
/** @type {MyInputData} */
var input = inputObj.data();
这个(只有 @typedef
和变量名称作为类型名称)似乎也可以在 PhpStorm 中工作:
/**
* @typedef {Object} input
* @property {string} connectto
* @property {string} othervalue
*/
var input = inputObj.data();
关于jquery - Jshint/PhpStorm : "Unresolved variable" when using jquery . 数据(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32993268/