[英]What exactly is .params and what does it do?
I'm currently working my way through Learning jQuery 4th edition, where i am given an example of a form which accepts one text input.The form, when submitted, searches through the jQuery docs for the string inputted, retrieves it as a JSONP object and displays it. 我目前正在学习jQuery第4版,其中给出了一个接受一个文本输入的表单示例。提交后,表单在jQuery文档中搜索输入的字符串,并将其作为JSONP对象检索并显示它。
In the example, i am given the following code extract 在示例中,我得到以下代码摘录
//more code
var buildItem = function(item) {
var title = item.name,
args = [],
output = '<li>';
if (item.type == 'method' || !item.type) {
if (item.signatures[0].params) {
$.each(item.signatures[0].params, function(index, val) {
args.push(val.name);
});
}
title = (/^jQuery|deferred/).test(title) ? title : '.' + title;
title += '(' + args.join(', ') + ')';
} else if (item.type == 'selector') {
title += ' selector';
}
output += '<h3><a href="' + item.url + '">' + title + '</a></h3>';
output += '<div>' + item.desc + '</div>';
output += '</li>';
return output;
};
//more code
i am having trouble understanding the line 我无法理解这条线
$.each(item.signatures[0].params, function(index, val) {
args.push(val.name);
});
specifically what does .params actually do? 具体来说,.params实际做什么? I understand that it is accessing .params from within the signatures in the object returned, but i do not see any .params in the returned object, nor can i seem to find any documentation on .params ..
我了解它正在从返回的对象的签名中访问.params,但是我在返回的对象中看不到任何.params,我似乎也找不到关于.params的任何文档。
Any help would be appreciated. 任何帮助,将不胜感激。
jsFiddle can be found here: http://jsfiddle.net/QPR4Z/2/ jsFiddle可以在这里找到: http : //jsfiddle.net/QPR4Z/2/
See the value in signatures[0]
- note that it is arbitrary data from a JSON request [for the jQuery API documentation]. 参见
signatures[0]
的值-请注意,它是来自JSON请求的任意数据 [用于jQuery API文档]。 That is, ".params" doesn't do anything, except function as normal property access. 也就是说,“。params”除了用作普通属性访问功能外不执行任何操作。 Despite syntax highlighting, it is not a reserved word and has no special meaning.
尽管突出显示了语法,但它不是保留字, 没有特殊含义。
Here is some relevant extracted JSON to illustrate the point: 以下是一些相关的提取JSON来说明这一点:
"signatures":[
{ // <-- i.e. signatures[0]
"added":"1.8",
"params":[ // <-- property called "params", which represents an array
// of objects that describe the given parameter
{"name":"selector","type":"Selector",..}
],
..
},
..
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.