Query String Object

授权协议 未知
开发语言
所属分类 jQuery 插件、 其他jQuery插件
软件类型 开源软件
地区 不详
投 递 者 张和豫
操作系统 未知
开源组织
适用人群 未知
 软件概览

This extension creates a singleton query string object for quick and readable query string modification and creation. This plugin provides a simple way of taking a page's query string and creating a modified version of this with little code.

Example

var url = location.search;
> "?action=view&section=info&id=123&debug&testy[]=true&testy[]=false&testy[]"
var section = $.query.get('section');
> "info"
var id = $.query.get('id');
> 123
var debug = $.query.get('debug');
> true
var arr = $.query.get('testy');
> ["true", "false", true]
var arrayElement = $.query.get('testy[1]');
> "false"
var newUrl = $.query.set("section", 5).set("action", "do").toString();
> "?action=do&section=5&id=123"
var newQuery = "" + $.query.set('type', 'string');
> "?action=view&section=info&id=123&type=string"
var oldQuery = $.query.toString();
> "?action=view&section=info&id=123"
var oldQuery2 = $.query;
> ?action=view&section=info&id=123
var newerQuery = $.query.SET('type', 'string');
> ?action=view&section=info&id=123&type=string
var notOldQuery = $.query.toString();
> "?action=view&section=info&id=123&type=string"
var oldQueryAgain = $.query.REMOVE("type");
> ?action=view&section=info&id=123
var emptyQuery = $.query.empty();
> ""
var stillTheSame = $.query.copy();
> ?action=view&section=info&id=123

Features

  • Chainability

    Like much of jQuery, this object supports chaining set methods to add new key value pairs to the object. In addition, this chain does not modify the original object, but returns a copy which can be modified without changing the original object. You can use the method the 'loud' alternate methods to perform destructive modifications on the original object.

  • Direct Object 'get' Accessor

    The query string object returned contains the keys of the query string through a method named 'get' (e.g. $.query.get(keypath)). Originally, they were also available through $.query[key] as well, but this was removed for version 1.2 since it let methods get removed and that's not fun for anyone.

  • Easy String Creation

    All modern browsers convert JavaScript objects to their string representation through their 'toString' method. So because this object creates a toString method for itself, when evaluated in a string context, this object returns a valid query string. If the query string object has no keys set, it returns an empty string. If it has keys set, it automatically prefixes the output with a question mark so you don't need to worry about appending one yourself. It's there if you need it and gone if you don't. It also supports arrays and associative arrays inside the query string. Both regular and associative arrays use "base[key1]=value1&base[key2]=value2" syntax in the query string. Originally arrays could forgo the square bracket and were simply printed out in their insertion order but with the new deep object support in version 2.0 this had to be removed for the sake of unambiguous keys. (However, I will maintain the 1.2 branch if requested. NB regarding v1.2, the bracketless form of array syntax doesn't create an array unless there is more than one key in the original query string.)

  • Query String Parsing

    The original url parsing code was created by Jörn Zaefferer and modified by me. The new parsing features added are:

    1. Parsing Integers

      The original code parsed floats out of strings but left integers as is. In my release, '123' will be converted to the number 123.

    2. Boolean Values

      Query strings can often contain query parameters with no value set. This implies a simple boolean. (eg index.php?debug implies a query string variable 'debug' set to true)

    3. Improved number parsing

      Parsing features introduced in version 1.2 include better support for number formats and differentiating between number-looking strings and numbers.

    4. Array syntax parsing

      Array shaped query string keys will create an array in the internal jQuery.query structure and using square brackets without an index will generate an array dynamically.

    5. Ampersand or semi-colon delimiters

      Because it has been requested of me, the parser now supports both semi-colons and ampersands as delimiting marks between key value pairs.

    6. Hash parameter parsing

      Because it has been requested of me, the parser now supports both query string parsing and parsing of query string like strings in the url hash.

  • Customization

    There are now some customizations which can be done, mostly dealing with parsing and with toString generation. The options are set by creating jQuery.query as an object of settings before including the jQuery.query source code on your page; when initializing, the query object will check the currently existing jQuery.query for any settings it can use. The settings are:

    1. separator

      The default value for this setting is '&' as that is the standard for parameter division. However, when working in xml, some prefer to use a semi-colon to separate parameters to avoid overuse of &. The parser has been updated to read semi-colons as delimiters but to output generated query strings with a semi-colon you need to set this setting to ';'

    2. space

      The default value for this is true as most people prefer plus signs in query strings to be converted to spaces. It's standard practice to use plus signs to represent spaces in query strings to avoid the dreaded %20 so the parser has been updated and, by default, converts plus signs to spaces. However, this feature can be disabled if you decide you need literal plus signs in your query strings.

    3. suffix

      The default for this is true. If set to true, any arrays, when outputted to a query string will be suffixed with "[]" to show them as an array more clearly. Some may prefer to generate array strings without the square brackets and can set this value to false. I set this to true by default because I prefer one element arrays to be unambiguously arrays when generated in a query string.

    4. hash

      The default for this is false. If set to true, the output of a query string will be prefixed by a hash '#' rather than a question mark. Given the interest in parsing hash parameters along with query string parameters, this seemed like a good setting to introduce.

    5. prefix

      The default for this is true. If set to false, the output of a query string is not prefixed by a hash or question mark.

Limitations

  • Direct Object Access

    Direct object access has been removed from this plugin as it wasn't symmetric (ie it was only usable for getting, not setting) and for safety reasons.

  • Boolean false Values

    Because true values are parsed and represented as attributes without distinct values, false is represented as a lack of attribute. Because of this, attempting to set an attribute to 'false' will result in its removal from the object. This is a design decision which may be made a customizable setting in the future.

  • Key Complexity

    Array and Object syntax in the system is designed for use with shallow objects and arrays. Future work could allow for nested arrays and objects, but that probably won't be done unless there is active interest in such a feature.

    Version 2.0 now supports deep objects just as well as PHP's built in $_GET object.

  • Submitted by blair on August 13, 2007 - 1:31pm This extension creates a singleton query string object for quick and readable query string modification and creation. This plugin provides a simple way o

  • 编写一个函数接受 url 中 query string 为参数, 返回解析后的 Object,query string 使用 application/x-www-form-urlencoded 编码 /** * 解析query string转换为对象,一个key有多个值时生成数组 * * @param {String} query 需要解析的query字符串,开头可以是?, * 按照app

  • 写在文章前 在long long ago ,还在喜欢写爬虫的时候,写过一个object转QueryString的小工具,最近复习反射部分,想起来贴出来哈 Object2QueryString 注解:LHttpQueryString import java.lang.annotation.ElementType; import java.lang.annotation.Retention; impo

  • //(赋值)最简单的一种hashMap赋值方式 List<HashMap<String, Object>> aMap= new ArrayList<HashMap<String,Object>>(); aMap.put("user","admin");//通过put加入一个键值 aMap.put("pwd","admin");  数据的遍历 //测试遍历数据 List<HashMap<String

  • Map<String, Object> paramMap = new HashMap<String, Object>();是什么意思? 意思是你的Map对象的键是String类型的,而值因为被定义为最上层的java对象Object对象,而所有的下级对象都隶属于Object对象,所以可以传任何类型的值在里面,比如,你可以这样: paramMap .put("userid","lianxue"); p

  • 一、安装 npm i -S query-string npm i -S qs 二、相同点 query-string 和 qs 都是用来把对象转成查询字符串或者把查询字符串转成对象用的,都有 parse 和 stringify 方法。两者大致能实现的效果是一样的,不同的是,query-string 更适合URL查询参数处理,qs能解析嵌套对象,而 query-string 则不行。axios 的 p

  • 获取url中的query string util方法: /*** * convert request query string to map * * @param queryString * @return */ public static Map<String, Object> parseQueryString(String queryString) { if (Va

  • hibernate使用原生sql查询时返回的字段不能重命名 例如使用如下sql查询时报错 sql = "SELECT t.type_name as `name`,SUM(o.circulation) FROM " + " t_info_product o " + " LEFT JOIN t_info_type t ON o.medi

  • 使用jpa的原生sql,将返回的记过封装到list map中是用的工具类 由于jpa对于左连接不支持,只能写原生的sql hql.append("SELECT u.id as id,u.account as account,u.name as userName,r.name as roleName,") .append(sql2) .append(",u.cardN

  • maven依赖: <!-- https://mvnrepository.com/artifact/commons-dbutils/commons-dbutils --> <dependency> <groupId>commons-dbutils</groupId> <artifactId>commons-dbutils</artifactId> <version>1.6</version>

  • package Test03; import JDBCUtils.JDBCUtils; import org.junit.Test; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import java.sql.Date;

  • public class Test(){ @PersistenceContext(unitName = "manageFactory") protected EntityManager em; public List<Map<String, Object>>getListMap(String sql){ Query nativeQuery=em.createNativeQuery(

  • 【报错】 :The method list(String, Object[]) is ambiguous for the type BaseHibernateDao<M,PK> 【解决】: 原因:eclipse 的个bug,具体见http://stackoverflow.com/questions/10852923/method-is-ambiguous-for-the-type-but-the-

  • List<Map<String,Object>> decompList = dao.query(sql1); 1.按某个字段抽取为List<String> List<String> ListName = decompList.stream().map(e -> e.get("NAME").toString()).collect(Collectors.toList()); 2.按2个字段,抽取为M

  • 获取List<Map<String, Object>>的值: List<Map<String, Object>> list =dao.queryTime(id); for(int j = 0 ; j < list.size() ; j ++){ // 打印"startTime"的值,Object转成String System.out.println("开始时间:"+String.valueOf

  • List<Map<String, Object>> List集合中的对象是一个Map对象,而这个Map对象的键是String类型,值是Object类型。 package com.huahua.test; import java.util.*; public class TestListMap { public static void main(String[] args) {

  • 在实验php反序列化的时候碰到了一点小问题,记录一下。 错误实例 下面这是源码,会产生一些问题,已经标识出来了 <?php class A{ public $name = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'; public $pass = '123456'; } $AA = new A(); $re

相关阅读

相关文章

相关问答

相关文档