Extjs Store findRecord query API
Here are some examples to illustrate the simple use of the Store findRecord method. For example, if you have a userStore and want to find a user named Felix (the premise is that the user model must have a user field), the query is as follows: 1var user = userStore. findRecord ('firstname', 'Felix '); the result of code execution above returns a Model instance. Let's look at a simple example. The requirement is to get the employee ID of Felix. The query is as follows: getUserID: function (name) {var userStore = this. getUserStore (); var user = userStore. findRecord ('name', 'Felix '); return user. get ('id') ;}good. Here I want to explain some limitations of the findRecord method: I can only find the first matched record. If the current store is filtered, the matched record can only be searched in the data set to be filtered, instead of the original store. In addition, the findRecord method has several parameters. It must be noted that fieldName (required ): field namevalue to be used as the query condition (required): the value of the query, matching the fieldName startIndex (optional): from which the store The default value is 0 anyMatch (Optional). The default value is match starting from the first character, similar to 'a % 'in SQL. If it is set to True, it is full match, similar to '% a %' in SQL. The default value is falsecaseSensitive (Optional). If it is set to true, Case sensitivity is enabled. The default value is falseexactMacth (Optional). If it is set to True, exact query is performed, the default value is false (^ and $ characters added to the regex ). for the last parameter exactMacth, it is worth noting that if the data in a store is [[['000000', 'po'], ['000000', 'so'], ['1 ', 'si'], model is {fieldOid, fieldName }. in this case, you need to find the filedName value of the record whose fieldOid is 1 (the correct result is SI) var field = fieldStore. fi NdRecord ('fieldid', '1'); var fieldName = field. get ('fieldname'); we think it should be okay to get the SI value, but the result is PO, why? I found an article on the Internet http://www.bkjia.com/kf/201306/218487.html said this is a bug in EXTJS, I think it should not. Because the value query is done through a regular expression, when 1 is passed in as a value, the API uses an expression similar to SQL 'a % 'for query. Of course, 145 is found, therefore, the returned result is PO. Therefore, the following query is required to query the expected records accurately: var field = fieldStore. findRecord ('fieldid', '1', 0, false, false, true); var fieldName = field. get ('fieldname ');