如何读取ExtJS 4中的查询字符串?

She*_*har 13 query-string extjs4

我有一个ExtJS应用程序,它使用一些查询字符串参数调用.我想知道如何使用ExtJS 4读取这些参数及其值.

我的ExtJS应用程序URL将如下所示:

http://localhost:8080/myapp?candidate_id=101&candidate_id=102&candidate_id=103
Run Code Online (Sandbox Code Playgroud)

Özg*_*ara 20

你可以Ext.Object.fromQueryString像这样 使用Ext.Object.fromQueryString('candidate_id=101&candidate_id=102&candidate_id=103')

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Object-method-fromQueryString

  • 使用`location.search`将参数传递给`Ext.Object.fromQueryString` (10认同)
  • 你可以通过`document.location.href.split('?')[1]`得到你的查询字符串,所以你可以使用这个值来表示**fromQueryString**方法.这个方法会给你一个对象.如果`candidate_id`不止一次提到它会给你一个`candidate_id`数组 (9认同)
  • 使用document.location.search比使用document.location.href.split(?)有很大的优势.如果网址中没有像http://www.google.de中那样给出搜索部分,则拆分将返回未定义的内容.这将导致Ext.Object.fromQueryString方法中的异常.使用document.location.search将返回一个空字符串,并且在没有提供搜索路径时不会崩溃!Thx Jaider (2认同)