.params到底是什么,它有什么作用? [英] What exactly is .params and what does it do?

查看:169
本文介绍了.params到底是什么,它有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习jQuery第4版,其中给出了一个接受一个文本输入的表单示例.提交后,表单在jQuery文档中搜索输入的字符串,并将其检索为JSONP对象并显示它.

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.

在示例中,我得到了以下代码摘录

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

我难以理解这条线

 $.each(item.signatures[0].params, function(index, val) {
              args.push(val.name);
            });

.params具体是做什么的?我了解它正在从返回的对象的签名中访问.params,但是我在返回的对象中看不到任何.params,我似乎也找不到关于.params的任何文档..

specifically what does .params actually do? 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 ..

任何帮助将不胜感激.

jsFiddle可以在这里找到: http://jsfiddle.net/QPR4Z/2/

jsFiddle can be found here: http://jsfiddle.net/QPR4Z/2/

推荐答案

请参见signatures[0]中的值-请注意,它是来自JSON请求的[strong>任意数据 [用于jQuery API文档].也就是说,.params"除了用作 normal 属性访问功能外,什么也不做.尽管突出显示了语法,但它不是 保留字,并且具有 no 特殊含义.

See the value in signatures[0] - note that it is arbitrary data from a JSON request [for the jQuery API documentation]. That is, ".params" doesn't do anything, except function as normal property access. Despite syntax highlighting, it is not a reserved word and has no special meaning.

以下是一些相关的提取JSON来说明这一点:

Here is some relevant extracted JSON to illustrate the point:

"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",..}
    ],
    ..
  },
  ..
]

这篇关于.params到底是什么,它有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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