core-options.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. <section>
  2. <h1 id="core-options" class="page-header">Core options</h1>
  3. <p>
  4. Select2 supports a small subset of options in every build that is
  5. generated. Each option typically has a decorator that is required that
  6. wraps an adapter, adding support for the option. This is only required
  7. when a custom adapter is being used, as Select2 will build the required
  8. adapters by default.
  9. </p>
  10. <p>
  11. Select2 will automatically apply decorators to any adapters which have not
  12. been manually overridden. The only time you need to decorate adapters is
  13. when you are using third-party adapters not provided by Select2, or you
  14. are using features not provided in the Select2 core. You can apply a
  15. decorator to an adapter using the
  16. <code title="select2/utils">Utils.Decorate</code> method provided with
  17. Select2.
  18. </p>
  19. <pre class="prettyprint linenums">
  20. $.fn.select2.amd.require(
  21. ["select2/utils", "select2/selection/single", "select2/selection/placeholder"],
  22. function (Utils, SingleSelection, Placeholder) {
  23. var CustomSelectionAdapter = Utils.Decorate(SingleSelection, Placeholder);
  24. });
  25. </pre>
  26. <p>
  27. All core options that use decorators or adapters will clearly state it
  28. in the "Decorator" or "Adapter" part of the documentation. Decorators are
  29. typically only compatible with a specific type of adapter, so make sure to
  30. note what adapter is given.
  31. </p>
  32. <h2 id="data-attributes">
  33. Declaring configuration in the <code>data-*</code> attributes
  34. </h2>
  35. <p>
  36. It is recommended that you declare your configuration options for Select2
  37. when initializing Select2. You can also define your configuration options
  38. by using the HTML5 <code>data-*</code> attributes, which will override
  39. any options set when initializing Select2 and any defaults.
  40. </p>
  41. <p>
  42. This means that if you declare your <code>&lt;select&gt;</code> tag as...
  43. </p>
  44. <pre class="prettyprint">
  45. &lt;select data-tags="true" data-placeholder="Select an option"&gt;&lt;/select&gt;
  46. </pre>
  47. <p>
  48. Will be interpreted the same as initializing Select2 as...
  49. </p>
  50. <pre class="prettyprint linenums">
  51. $("select").select2({
  52. tags: "true",
  53. placeholder: "Select an option"
  54. });
  55. </pre>
  56. <p>
  57. You can also define nested configurations, which are typically needed for
  58. options such as AJAX. Each level of nesting should be separated by two
  59. dashes (<code>--</code>) instead of one. Due to
  60. <a href="https://github.com/jquery/jquery/issues/2070">a jQuery bug</a>,
  61. nested options using <code>data-*</code> attributes
  62. <a href="https://github.com/select2/select2/issues/2969">do not work in jQuery 1.x</a>.
  63. </p>
  64. <pre class="prettyprint">
  65. &lt;select data-ajax--url="http://example.org/api/test" data-ajax--cache="true"&gt;&lt;/select&gt;
  66. </pre>
  67. <p>
  68. Which will be interpreted the same as initializing Select2 with...
  69. </p>
  70. <pre class="prettyprint linenums">
  71. $("select").select2({
  72. ajax: {
  73. url: "http://example.org/api/test",
  74. cache: "true"
  75. }
  76. });
  77. </pre>
  78. <p>
  79. The value of the option is subject to jQuery's
  80. <a href="https://api.jquery.com/data/#data-html5">parsing rules</a> for
  81. HTML5 data attributes.
  82. </p>
  83. <h2 id="amd">
  84. AMD compatibility
  85. </h2>
  86. <p>
  87. You can find more information on how to integrate Select2 with your
  88. existing AMD-based project by
  89. <a href="announcements-4.0.html#builds">viewing the 4.0 release notes</a>.
  90. Select2 automatically loads some modules when the adapters are being
  91. automatically constructed, so those who are using Select2 with a custom
  92. AMD build using their own system may need to specify the paths that are
  93. generated to the Select2 modules.
  94. </p>
  95. <div class="row">
  96. <div class="col-sm-6">
  97. <dl class="dl-horizontal">
  98. <dt>Key</dt>
  99. <dd>
  100. <code>amdBase</code>
  101. </dd>
  102. <dt>Default</dt>
  103. <dd>
  104. <code>select2/</code>
  105. </dd>
  106. </dl>
  107. </div>
  108. <div class="col-sm-6">
  109. <dl class="dl-horizontal">
  110. <dt>Key</dt>
  111. <dd>
  112. <code>amdLanguageBase</code>
  113. </dd>
  114. <dt>Default</dt>
  115. <dd>
  116. <code>select2/i18n/</code>
  117. </dd>
  118. </dl>
  119. </div>
  120. </div>
  121. <h2 id="core-options-display">
  122. Displaying selections
  123. </h2>
  124. <p>
  125. Select2 provides options that allow you to directly affect how the
  126. container that holds the current selection is displayed.
  127. </p>
  128. <h3 id="placeholder">
  129. Placeholders
  130. </h3>
  131. <p>
  132. Select2 can display a placeholder for a single-value select that will
  133. replace an option, or be shown when no options are selected for
  134. multiple-value selects. You can find an example on the
  135. <a href="examples.html#placeholders">example page</a>.
  136. </p>
  137. <div class="row">
  138. <div class="col-sm-6">
  139. <dl class="dl-horizontal">
  140. <dt>Key</dt>
  141. <dd>
  142. <code>placeholder</code>
  143. </dd>
  144. <dt>Value</dt>
  145. <dd>string or object</dd>
  146. </dl>
  147. <hr />
  148. <dl class="dl-horizontal">
  149. <dt>Adapter</dt>
  150. <dd>
  151. <code title="select2/selection/base">SelectionAdapter</code>
  152. </dd>
  153. <dt>Decorator</dt>
  154. <dd>
  155. <code title="select2/selection/placeholder">Placeholder</code>
  156. and
  157. <code title="select2/dropdown/hidePlaceholder">HidePlaceholder</code>
  158. </dd>
  159. </dl>
  160. </div>
  161. <div class="col-sm-6">
  162. <div class="alert alert-warning">
  163. <strong>Heads up!</strong>
  164. Because browsers assume that the first <code>option</code> in
  165. single-value select boxes is selected, you should add an empty
  166. <code>&lt;option&gt;&lt;/option&gt;</code> tag that the placeholder
  167. should use or it may not work.
  168. </div>
  169. </div>
  170. </div>
  171. <p>
  172. If the <strong>value is a string</strong>, the placeholder will be
  173. displayed when a <strong>blank option</strong> is used as the placeholder.
  174. The <strong>value</strong> will be the message to show to users as the
  175. placeholders.
  176. </p>
  177. <pre class="prettyprint">
  178. placeholder: "Select a repository"
  179. </pre>
  180. <p>
  181. If the <strong>value is an object</strong>, the object should be
  182. compatible with Select2's internal objects. The <code>id</code> should
  183. be the id to look for when determining if the placeholder should be
  184. displayed. The <code>text</code> should be the placeholder to display
  185. when that option is selected.
  186. </p>
  187. <pre class="prettyprint linenums">
  188. placeholder: {
  189. id: "-1",
  190. text: "Select a repository"
  191. }
  192. </pre>
  193. <div class="alert alert-info">
  194. You should <strong>pass in an object</strong> when you are using a
  195. framework that <strong>creates its own placeholder option</strong>. The
  196. <strong>id</strong> should be the same as the <code>value</code>
  197. attribute on the <code>option</code>.
  198. </div>
  199. <p id="allowClear">
  200. You can allow a selected option to be cleared back to the placeholder by
  201. enabling the <code>allowClear</code> option.
  202. </p>
  203. <div class="row">
  204. <div class="col-sm-6">
  205. <dl class="dl-horizontal">
  206. <dt>Key</dt>
  207. <dd><code>allowClear</code></dd>
  208. <dt>Value</dt>
  209. <dd>boolean</dd>
  210. </dl>
  211. </div>
  212. <div class="col-sm-6">
  213. <dl class="dl-horizontal">
  214. <dt>Adapter</dt>
  215. <dd>
  216. <code title="select2/selection/base">SelectionAdapter</code>
  217. </dd>
  218. <dt>Decorator</dt>
  219. <dd>
  220. <code title="select2/selection/allowClear">AllowClear</code>
  221. </dd>
  222. </dl>
  223. </div>
  224. </div>
  225. <p>
  226. This will display an "x" that the user can click to clear the current
  227. selection. It is designed to be used for cases where a single selection
  228. can be made.
  229. </p>
  230. <h3 id="multiple">
  231. Multiple selections
  232. </h3>
  233. <p>
  234. Select2 can display either a single selection or multiple selections.
  235. </p>
  236. <dl class="dl-horizontal">
  237. <dt>Key</dt>
  238. <dd><code>multiple</code></dd>
  239. <dt>Value</dt>
  240. <dd>boolean (<code>true</code> or <code>false</code>)</dd>
  241. </dl>
  242. <p>
  243. This option will determine what the <code>SelectAdapter</code> (used by
  244. default) should use to set the value of the underlying <code>select</code>
  245. element. It will also determine if the <code>MultipleSelection</code>
  246. adapter should be used.
  247. </p>
  248. <h3 id="width">
  249. Container width
  250. </h3>
  251. <p>
  252. Select2 will try to match the width of the original element as closely as
  253. possible. Sometimes this isn't perfect, which is what you can tell Select2
  254. how to determine the width.
  255. </p>
  256. <div class="row">
  257. <div class="col-sm-6">
  258. <table class="table table-striped table-bordered">
  259. <thead>
  260. <tr>
  261. <th>Value</th>
  262. <th>Description</th>
  263. </tr>
  264. </thead>
  265. <tbody>
  266. <tr>
  267. <td><code>"element"</code></td>
  268. <td>
  269. Uses javascript to calculate the width of the source element.
  270. </td>
  271. </tr>
  272. <tr>
  273. <td><code>"style"</code></td>
  274. <td>
  275. Copies the value of the width <code>style</code> attribute set on the source element.
  276. </td>
  277. </tr>
  278. <tr>
  279. <td><code>"resolve"</code></td>
  280. <td>
  281. Tries to use <code>style</code> to determine the width, falling back to <code>element</code>.
  282. </td>
  283. </tr>
  284. <tr>
  285. <td>Anything else</td>
  286. <td>
  287. The value of the <code>width</code> option is directly set as the width of the container.
  288. </td>
  289. </tr>
  290. </tbody>
  291. </table>
  292. </div>
  293. <div class="col-sm-6">
  294. <dl class="dl-horizontal">
  295. <dt>Key</dt>
  296. <dd><code>width</code></dd>
  297. <dt>Value</dt>
  298. <dd>string</dd>
  299. </dl>
  300. </div>
  301. </div>
  302. <h3 id="language">
  303. Internationalization (Language support)
  304. </h3>
  305. <p>
  306. Messages will be displayed to users when necessary, such as when no
  307. search results were found or more characters need to be entered in order
  308. for a search to be made. These messages have been
  309. <a href="community.html#translations">translated into many languages</a>
  310. by contributors to Select2, but you can also provide your own
  311. translations.
  312. </p>
  313. <div class="row">
  314. <div class="col-sm-6">
  315. <dl class="dl-horizontal">
  316. <dt>Key</dt>
  317. <dd><code>language</code></dd>
  318. <dt>Value</dt>
  319. <dd>object or string</dd>
  320. </dl>
  321. <hr />
  322. <dl class="dl-horizontal">
  323. <dt>Module</dt>
  324. <dd>
  325. <code title="select2/translation">Translation</code>
  326. </dd>
  327. </dl>
  328. </div>
  329. <div class="col-sm-6">
  330. <p class="alert alert-warning">
  331. <strong>Heads up!</strong> When using translations provided by Select2,
  332. you must make sure to include the translation file in your page after
  333. Select2.
  334. </p>
  335. </div>
  336. </div>
  337. <p>
  338. When a string is passed in as the language, Select2 will try to resolve
  339. it into a language file. This allows you to specify your own language
  340. files, which must be defined as an AMD module. If the language file
  341. cannot be found, Select2 will assume it is a language code controlled by
  342. Select2, and it will try to load the translations for that language
  343. instead.
  344. </p>
  345. <p>
  346. You can include your own translations by providing an object similar to
  347. the one below.
  348. </p>
  349. <pre class="prettyprint linenums">
  350. language: {
  351. // You can find all of the options in the language files provided in the
  352. // build. They all must be functions that return the string that should be
  353. // displayed.
  354. inputTooShort: function () {
  355. return "You must enter more characters...";
  356. }
  357. }
  358. </pre>
  359. <h3 id="templating">
  360. Templating results and selections
  361. </h3>
  362. <p>
  363. By default, Select2 will display the option text within the list of
  364. results and when the option has been selected. Select2 comes with options
  365. that allow you to further customize the display of results and selections,
  366. allowing you to display them however you want.
  367. </p>
  368. <h4 id="templateSelection">
  369. Customizing the display of selections
  370. </h4>
  371. <p>
  372. When an option is displayed after it has been selected, it is passed
  373. through a formatting function that determines what is displayed. By
  374. default, the function only returns the <code>text</code> key of the data
  375. object.
  376. </p>
  377. <dl class="dl-horizontal">
  378. <dt>Key</dt>
  379. <dd><code>templateSelection</code></dd>
  380. <dt>Value</dt>
  381. <dd>A function taking a <code>selection</code> object</dd>
  382. </dl>
  383. <div class="alert alert-info">
  384. <strong>Anything rendered as a selection is templated.</strong>
  385. This includes placeholders and pre-existing selections that are displayed,
  386. so you must ensure that your templating functions can support them.
  387. </div>
  388. <p>
  389. The <code>templateSelection</code> function should return a string
  390. containing the text to be displayed, or an object (such as a jQuery
  391. object) that contains the data that should be displayed.
  392. </p>
  393. <p>
  394. <strong>Strings are assumed to contain only text</strong> and will be
  395. passed through the <code>escapeMarkup</code> function, which strips any
  396. HTML markup.
  397. </p>
  398. <p>
  399. <strong>
  400. Anything else will be passed
  401. <a href="https://api.jquery.com/append/">directly to <code>jQuery.fn.append</code></a>
  402. </strong> and will be handled directly by jQuery. Any markup, such as
  403. HTML, returned will not be escaped and it is up to you to escape any
  404. malicious input provided by users.
  405. </p>
  406. <h4 id="templateResult">
  407. Customizing the display of results
  408. </h4>
  409. <p>
  410. When an option is displayed after it has been selected, it is passed
  411. through a formatting function that determines what is displayed. By
  412. default, the function only returns the <code>text</code> key of the data
  413. object.
  414. </p>
  415. <dl class="dl-horizontal">
  416. <dt>Key</dt>
  417. <dd><code>templateSelection</code></dd>
  418. <dt>Value</dt>
  419. <dd>A function taking a <code>selection</code> object</dd>
  420. </dl>
  421. <div class="alert alert-info">
  422. <strong>Anything rendered in the results is templated.</strong>
  423. This includes results such as the "Searching..." and "Loading more..."
  424. text which will periodically be displayed, which allows you to add more
  425. advanced formatting to these automatically generated options.
  426. </div>
  427. <p>
  428. The <code>templateResult</code> function should return a string
  429. containing the text to be displayed, or an object (such as a jQuery
  430. object) that contains the data that should be displayed. It can also
  431. return <code>null</code>, which will prevent the option from being
  432. displayed in the results list.
  433. </p>
  434. <p>
  435. <strong>Strings are assumed to contain only text</strong> and will be
  436. passed through the <code>escapeMarkup</code> function, which strips any
  437. HTML markup.
  438. </p>
  439. <p>
  440. <strong>
  441. Anything else will be passed
  442. <a href="https://api.jquery.com/append/">directly to <code>jQuery.fn.append</code></a>
  443. </strong> and will be handled directly by jQuery. Any markup, such as
  444. HTML, returned will not be escaped and it is up to you to escape any
  445. malicious input provided by users.
  446. </p>
  447. <h2 id="core-options-results">
  448. Returning and displaying results
  449. </h2>
  450. <p>
  451. Select2 can work on many different data sets ranging from local options,
  452. the same way that a <code>&lt;select&gt;</code> typically works, from
  453. remote options where a server generates the results that users can select
  454. from.
  455. </p>
  456. <h3 id="data">
  457. Array
  458. </h3>
  459. <p>
  460. Select2 allows creating the results based on an array of data objects that
  461. is included when initializing Select2.
  462. </p>
  463. <div class="row">
  464. <div class="col-sm-6">
  465. <dl class="dl-horizontal">
  466. <dt>Key</dt>
  467. <dd><code>data</code></dd>
  468. <dt>Value</dt>
  469. <dd>array of objects</dd>
  470. </dl>
  471. </div>
  472. <div class="col-sm-6">
  473. <dl class="dl-horizontal">
  474. <dt>Adapter</dt>
  475. <dd>
  476. <code title="select2/data/array">ArrayAdapter</code>
  477. </dd>
  478. </dl>
  479. </div>
  480. </div>
  481. <p>
  482. The objects that the users can select from should be passed as an array
  483. with each object containing <code>id</code> and <code>text</code>
  484. properties.
  485. </p>
  486. <h3 id="ajax">
  487. AJAX
  488. </h3>
  489. <p>
  490. Select2 allows searching for results from remote data sources using AJAX
  491. requests.
  492. </p>
  493. <div class="row">
  494. <div class="col-sm-6">
  495. <dl class="dl-horizontal">
  496. <dt>Key</dt>
  497. <dd><code>ajax</code></dd>
  498. <dt>Value</dt>
  499. <dd>object</dd>
  500. </dl>
  501. </div>
  502. <div class="col-sm-6">
  503. <dl class="dl-horizontal">
  504. <dt>Adapter</dt>
  505. <dd>
  506. <code title="select2/data/ajax">AjaxAdapter</code>
  507. </dd>
  508. </dl>
  509. </div>
  510. </div>
  511. <p>
  512. All options passed to this option will be directly passed to the
  513. <code>$.ajax</code> function that executes AJAX requests. There are a few
  514. custom options that Select2 will intercept, allowing you to customize the
  515. request as it is being made.
  516. <pre class="prettyprint linenums">
  517. ajax: {
  518. // The number of milliseconds to wait for the user to stop typing before
  519. // issuing the ajax request.
  520. delay: 250,
  521. // You can craft a custom url based on the parameters that are passed into the
  522. // request. This is useful if you are using a framework which has
  523. // JavaScript-based functions for generating the urls to make requests to.
  524. //
  525. // @param params The object containing the parameters used to generate the
  526. // request.
  527. // @returns The url that the request should be made to.
  528. url: function (params) {
  529. return UrlGenerator.Random();
  530. },
  531. // You can pass custom data into the request based on the parameters used to
  532. // make the request. For `GET` requests, the default method, these are the
  533. // query parameters that are appended to the url. For `POST` requests, this
  534. // is the form data that will be passed into the request. For other requests,
  535. // the data returned from here should be customized based on what jQuery and
  536. // your server are expecting.
  537. //
  538. // @param params The object containing the parameters used to generate the
  539. // request.
  540. // @returns Data to be directly passed into the request.
  541. data: function (params) {
  542. var queryParameters = {
  543. q: params.term
  544. }
  545. return queryParameters;
  546. },
  547. // You can modify the results that are returned from the server, allowing you
  548. // to make last-minute changes to the data, or find the correct part of the
  549. // response to pass to Select2. Keep in mind that results should be passed as
  550. // an array of objects.
  551. //
  552. // @param data The data as it is returned directly by jQuery.
  553. // @returns An object containing the results data as well as any required
  554. // metadata that is used by plugins. The object should contain an array of
  555. // data objects as the `results` key.
  556. processResults: function (data) {
  557. return {
  558. results: data
  559. };
  560. },
  561. // You can use a custom AJAX transport function if you do not want to use the
  562. // default one provided by jQuery.
  563. //
  564. // @param params The object containing the parameters used to generate the
  565. // request.
  566. // @param success A callback function that takes `data`, the results from the
  567. // request.
  568. // @param failure A callback function that indicates that the request could
  569. // not be completed.
  570. // @returns An object that has an `abort` function that can be called to abort
  571. // the request if needed.
  572. transport: function (params, success, failure) {
  573. var $request = $.ajax(params);
  574. $request.then(success);
  575. $request.fail(failure);
  576. return $request;
  577. }
  578. }
  579. </pre>
  580. </p>
  581. <h3 id="tags">
  582. Tags
  583. </h3>
  584. <p>
  585. Users can create their own options based on the text that they have
  586. entered.
  587. </p>
  588. <div class="row">
  589. <div class="col-sm-6">
  590. <dl class="dl-horizontal">
  591. <dt>Key</dt>
  592. <dd><code>tags</code></dd>
  593. <dt>Value</dt>
  594. <dd>boolean / array of objects</dd>
  595. </dl>
  596. </div>
  597. <div class="col-sm-6">
  598. <dl class="dl-horizontal">
  599. <dt>Adapter</dt>
  600. <dd>
  601. <code title="select2/data/base">DataAdapter</code>
  602. </dd>
  603. <dt>Decorator</dt>
  604. <dd>
  605. <code title="select2/data/tags">Tags</code>
  606. </dd>
  607. </dl>
  608. </div>
  609. </div>
  610. <p>
  611. If the <code>tags</code> option is passed into Select2, if a user types
  612. anything into the search box which doesn't already exist, it will be
  613. displayed at the top and the user will be able to select it.
  614. </p>
  615. <p>
  616. <strong>For backwards compatibility</strong>, if an array of objects is
  617. passed in with the <code>tags</code> option, the options will be
  618. automatically created and the user will be able to select from them.
  619. This is the <strong>same as how <a href="#data">array data</a>
  620. works</strong>, and has similar limitations.
  621. </p>
  622. <h3 id="matcher">
  623. Change how options are matched when searching
  624. </h3>
  625. <p>
  626. When users filter down the results by entering search terms into the
  627. search box, Select2 uses an internal "matcher" to match search terms to
  628. results. <strong>When a remote data set is used, Select2 expects that the
  629. returned results have already been filtered.</strong>
  630. </p>
  631. <dl class="dl-horizontal">
  632. <dt>Key</dt>
  633. <dd>
  634. <code>matcher</code>
  635. </dd>
  636. <dt>Value</dt>
  637. <dd>
  638. A function taking search <code>params</code> and the
  639. <code>data</code> object.
  640. </dd>
  641. </dl>
  642. <p>
  643. Select2 will pass the individual data objects that have been passed back
  644. from the data adapter into the <code>matcher</code> individually to
  645. determine if they should be displayed. Only the first-level objects will
  646. be passed in, so <strong>if you are working with nested data, you need to
  647. match those individually</strong>.
  648. </p>
  649. <pre class="prettyprint linenums">
  650. matcher: function (params, data) {
  651. // If there are no search terms, return all of the data
  652. if ($.trim(params.term) === '') {
  653. return data;
  654. }
  655. // `params.term` should be the term that is used for searching
  656. // `data.text` is the text that is displayed for the data object
  657. if (data.text.indexOf(params.term) > -1) {
  658. var modifiedData = $.extend({}, data, true);
  659. modifiedData.text += ' (matched)';
  660. // You can return modified objects from here
  661. // This includes matching the `children` how you want in nested data sets
  662. return modifiedData;
  663. }
  664. // Return `null` if the term should not be displayed
  665. return null;
  666. }
  667. </pre>
  668. <p>
  669. This allows for more advanced matching when working with nested objects,
  670. allowing you to handle them however you want. For those who are not
  671. looking to implement highly customized matching, but instead are just
  672. looking to change the matching algorithm for the text, a
  673. <a href="#compat-matcher">compatibility modules</a> has been created to
  674. make it easier.
  675. </p>
  676. </section>