2017-11-29 5 views
0

Ich bin völlig neu in Javascript und ich habe eine Frage über die Auswahl Bibliothek. Wie kann ich etwas zur Liste hinzufügen und auswählen?Artikel zur Auswahl hinzufügen

{% block head %} 
<link rel="stylesheet" href="{% static 'plugins/selectize/dist/css/selectize.default.css' %}"> 
<script type="text/javascript" src="{% static 'plugins/selectize/dist/js/standalone/selectize.js' %}"></script> 

<script type="text/javascript"> 
    $(function() { 

    var options=[ 
     {value:0, text:"option 0"}, 
     {value:1, text:"option 1"}, 
     {value:2, text:"option 2"}, 
     {value:3, text:"option 3"}, 
    ]; 

     $('show_something').selectize({ 
     plugins: ['remove_button', 'restore_on_backspace'], 
     options: 'options' 
     }); 
    }); 
</script> 
{% endblock %} 

{% block content %} 
<form method="post"> 
<label>whatever 
    <show_something></show_something> 
</label> 

Und ich kann nichts damit machen. Und ich muss option 0 und option 1 standardmäßig auswählen und Möglichkeiten haben, option 2 und option 3 zu wählen.

Ich kann keine Informationen finden, wie man das einfach macht.

Antwort

0

Ok ich weiß jetzt: P halbe Stunde mehr googeln: P

{% block head %} 
<link rel="stylesheet" href="{% static 
'plugins/selectize/dist/css/selectize.default.css' %}"> 
<script type="text/javascript" src="{% static 
'plugins/selectize/dist/js/standalone/selectize.js' %}"></script> 

<script type="text/javascript"> 
    $(function() { 

var options1=[{ 
       value: 0, 
       title: 'option 0', 
      }, { 
       value: 1, 
       title: 'option 1', 
      }, { 
       value: 2, 
       title: 'option 2', 
      }, { 
       value: 3, 
       title: 'option 2', 
     }]; 

    $('#show_something').selectize({ 
      plugins: ['remove_button', 'restore_on_backspace'], 
      maxItems: null, 
      valueField: 'value', 
      labelField: 'title', 
      searchField: 'title', 
      options: options1, 
      create: false 
     }); 
}); 
</script> 
{% endblock %} 

{% block content %} 
<form method="post"> 
<selectize id="show_something" multiple="multiple" placeholder="whatever" 
style="width:100px; height:25px;" class="selectized"></selectize> 
</form> 
Verwandte Themen