require(["esri/lang"], function(esriLang) { /* code goes here */ });
esri.filter()
.Name | Return type | Summary |
---|---|---|
filter(object, callback, thisObject?) | Object | Creates a new object with all properties that pass the test implemented by the filter provided in the function. |
isDefined(value) | Boolean | Returns true when the value is neither null or undefined. |
stripTags(value) | Object | String | Strips HTML tags from a String or Object. |
substitute(data, template?, options?) | String | A wrapper around dojo.string.substitute that can also handle wildcard substitution. |
valueOf(array, value) | Object | Iterates through the argument array and searches for the identifier to which the argument value matches. |
Object
< > object |
Required | Object to filter. |
< > callback |
Required | Function or string implementing the filtering. |
< > thisObject |
Optional | Optional object used to scope the call to the callback. |
require([ "esri/lang", "dojo/dom", ... ], function(esriLang, dom, ... ) { function showResults(results) { var filterFunction = function(value) { if ((value !== ' ') & (Number(value) !== 0)) { return true; }; }; var filteredResults = esriLang.filter(results.features[0].attributes, filterFunction); var s = ""; for (att in filteredResults) { s = s + "<b>" + att + ":</b> " + filteredResults[att] + "<br />"; }; dom.byId("info").innerHTML = s; }; ... });
Boolean
< > value |
Required | The value to test. |
require(["esri/lang", "dojo/domReady!"], function(esriLang) { var myobj = { name: "<b>Jane</b>", //myobj.name = "<b>Jane</b>" last: "Doe", age: "30" }; esriLang.stripTags(myobj); console.log(myobj); //myobj.name = "Jane" });
String
< > data |
Required | The data object used in the substitution. |
< > template |
Optional | The template used for the substitution. Can be any valid HTML. If no template is included, the wildcard template is used. |
< > options |
Optional | Object containing a format object used in the substitution. |
options
>< > format |
Optional | This object contains key:value pairs where the key is either a
value object supports formatType property. This can be one of the following types:
|
require(["esri/lang", ... ], function(esriLang, ... ) { ... });
esriLang.substitute({state_name: "Arizona", state_capital: "Phoenix"});Returns:
state_name = Arizona state_capital = Phoenix
esriLang.substitute({state_name: "Arizona", state_capital: "Phoenix"},null,true);Returns:
state_name = Arizona
var data = { a: 123456, b: 1000000 }; // The first example shows the key as a field name esriLang.substitute(data, "Number = ${fieldA}, Date = ${fieldB}", { format: { fieldA: { formatType: "NumberFormat", places: 2 }, fieldB: { formatType: "DateFormat", datePattern: "y", selector: "date" } } }); // The second example shows the key as a user-defined identifier specified beside the field name in the template string esriLang.substitute(data, "Year = ${fieldB:yearOnly}, Full Date = ${fieldB:fullDate}", { format: { yearOnly: { formatType: "DateFormat", datePattern: "y", selector: "date" }, fullDate: { formatType: "DateFormat", datePattern: "M/d/y", timePattern: "h:mm:ss a", selector: "date and time" } } });Returns:
First returns Number = 123,456.00, Date = 1969 whereas the second example returns Year = 1969, Full Date = 12/31/1969, 7:16:40 PM (this reflects the returned values at date/time of documention).
Object
< > array |
Required | The argument array for testing. |
< > value |
Required | The value used in the search. If the value is a String, the value is case sensitive. |
Example 1:
require([ "esri/lang", ... ], function(esriLang, ... ) { esriLang.valueOf([firststring: "Oregon", secondstring: "Washington"], "Washington"); ... });
Returns: secondstring
Example 2:
require([ "esri/lang", ... ], function(esriLang, ... ) { esriLang.valueOf([firststring: "Oregon", secondstring: "Washington"], "Virginia"); ... });
Returns: null