1 Array.prototype.contains = function(obj) { 2 var i = this.length; 3 while (i--) { 4 if (this[i] === obj) { 5 return true; 6 } 7 } 8 return false; 9 };10 // 查询函数11 var tempIndex=[];12 function searchText(dg,t){ //参数:$("#datagrid"),$(”#text“)13 var dg = objs.addFoodsListGrid;14 var t = $('#searchFoodsList');15 16 dg.datagrid("unselectAll");17 var rows = dg.datagrid("getData").rows;18 console.log(rows);19 var columns = dg.datagrid('getColumnFields');20 console.log(columns);21 var searchVal = t.val();22 for(var i=0;i=0){25 if(!tempIndex.contains(i)){26 dg.datagrid("selectRow",i);27 tempIndex.push(i);28 return;29 }30 }31 }32 if(i==(rows.length-1)){33 tempIndex=[];34 }35 }36 }