jLinq具有动态选择功能

时间:2015-06-24 12:27:35

标签: jquery linq select

我正在使用jLinq来查询Array Objects的{​​{1}} 但我想动态查询获取Selects

的值

这是我的例子:

<select id="firt"><option>Select 1</option></select>
<select id="last"><option>Select 2</option></select>
<select id="phone"><option>Select 3</option></select>

myNewArray = jlinq.from( array ).sort( "date" )
             .equals( "first", $( "#first" ).find( "option:selected" )  
             .equals( "last",  $( "#last" ).find( "option:selected" )
             .equals( "phone", $( "#phone" ).find( "option:selected" )
             .group( "state" );

但我想要这样的事情:

myNewArray = jlinq.from( array ).sort( "date" )
             //for each selected option
             .group( "state" );

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

function makeQuery() {
  var query = 'jlinq.from( array ).sort( "date" )';

  $('select').each(function(index) {
    query += '.equals( "' + this.id + '", "' + this.value + '")';
  });

  query += '.group( "state" );'

  $('#query').html(query);

  //myNewArray = eval(query);
}