dropdown <select> for list.js

試著忘記壹切 提交于 2019-12-10 19:58:08

问题


list.js is using search box as default. Anyone know, how to use dropdown selection box for list.js?

I have used:

Javascript:

<script type="text/javascript">
$('#tpi').change(function () {
    var selection = this.value; //grab the value selected
var options = { valueNames: [ 'name', 'type', 'tpi' ]
};
var userList = new List('users', options);  
   });
</script>

HTML

      <select name="tpi" id="tpi">
        <option selected="selected" value="tpi">TPI</option>
        <option value="11">11</option>
        <option value="14">14</option>
        <option value="16">16</option>
        <option value="18">18</option>
        <option value="19">19</option>
      </select>

But not working. :(


回答1:


Try something like this:

var options = {
    valueNames: ['name', 'type', 'tpi']
};
var userList = new List('users', options);

$('#tpi').change(function () {
    var selection = this.value; 

    // filter items in the list
    userList.filter(function (item) {
        return (item.values().tpi == selection);
    });

});

Make sure you place this script below the html stuff that needs to be filtered.



来源:https://stackoverflow.com/questions/20674095/dropdown-select-for-list-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!