Merge pull request #177 from inmarelibero/gh-pages
added "add reference to original option element" in doc
This commit is contained in:
commit
f4ddeee6b2
33
index.html
33
index.html
@ -25,6 +25,7 @@ version: 2.1
|
|||||||
<script id="script_e4">
|
<script id="script_e4">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
function format(state) {
|
function format(state) {
|
||||||
|
// original <option> or <optgroup> element is accessible by property state.element
|
||||||
return "<img class='flag' src='images/flags/" + state.id.toLowerCase() + ".png'/>" + state.text;
|
return "<img class='flag' src='images/flags/" + state.id.toLowerCase() + ".png'/>" + state.text;
|
||||||
}
|
}
|
||||||
$("#e4").select2({
|
$("#e4").select2({
|
||||||
@ -340,6 +341,22 @@ version: 2.1
|
|||||||
<div class="span8">
|
<div class="span8">
|
||||||
<h3>Example Code</h3>
|
<h3>Example Code</h3>
|
||||||
<pre class="prettyprint linenums" id="code_e4"></pre>
|
<pre class="prettyprint linenums" id="code_e4"></pre>
|
||||||
|
<p>
|
||||||
|
You can set <code>data-</code> attributes to <code><option></code> (or <optgroup>) and use them inside temptlating functions:
|
||||||
|
</p>
|
||||||
|
<pre class="prettyprint linenums">
|
||||||
|
<select>
|
||||||
|
<option value="0" data-foo="bar">option one</option>
|
||||||
|
...
|
||||||
|
</select>
|
||||||
|
</pre>
|
||||||
|
<pre class="prettyprint linenums">
|
||||||
|
function format(state) {
|
||||||
|
var originalOption = state.element;
|
||||||
|
|
||||||
|
return "<img class='flag' src='images/flags/" + state.id.toLowerCase() + ".png' alt='" + originalOption.data('foo') + "' />" + state.text;
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
@ -773,6 +790,14 @@ version: 2.1
|
|||||||
<tr><td><returns></td><td>string</td><td>Html that represents the selection</td></tr>
|
<tr><td><returns></td><td>string</td><td>Html that represents the selection</td></tr>
|
||||||
</table>
|
</table>
|
||||||
The default implementation expects the object to have a <code>text</code> property that is returned.
|
The default implementation expects the object to have a <code>text</code> property that is returned.
|
||||||
|
<br><br>
|
||||||
|
Original <code><option></code> (or <optgroup>) element is accessible inside the specified function through the property <code>item.element</code>:
|
||||||
|
<pre>
|
||||||
|
format(item) {
|
||||||
|
var originalOption = item.element;
|
||||||
|
// return item.text
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
<tr><td>formatResult</td><td>function</td><td>
|
<tr><td>formatResult</td><td>function</td><td>
|
||||||
Function used to render a result that the user can select.
|
Function used to render a result that the user can select.
|
||||||
@ -783,6 +808,14 @@ version: 2.1
|
|||||||
<tr><td><returns></td><td>string</td><td>Html that represents the result</td></tr>
|
<tr><td><returns></td><td>string</td><td>Html that represents the result</td></tr>
|
||||||
</table>
|
</table>
|
||||||
The default implementation expects the object to have a <code>text</code> property that is returned.
|
The default implementation expects the object to have a <code>text</code> property that is returned.
|
||||||
|
<br><br>
|
||||||
|
Original <code><option></code> (or <optgroup>) element is accessible inside the specified function through the property <code>item.element</code>:
|
||||||
|
<pre>
|
||||||
|
format(item) {
|
||||||
|
var originalOption = item.element;
|
||||||
|
// return item.text
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
<tr><td>formatNoMatches</td><td>function</td><td>
|
<tr><td>formatNoMatches</td><td>function</td><td>
|
||||||
Function used to render the "No matches" message
|
Function used to render the "No matches" message
|
||||||
|
Loading…
Reference in New Issue
Block a user