PDA

View Full Version : How build pattern of regular expression ?



caam
25 Apr 2008, 4:08 AM
Hi,

The second argument of filter method of JsonView accept a regular expression. The regular expression is not a string. It is not between quote.

Example :


pattern = /['0'|'1']/; //or pattern = /[0|1]/
view.filter('MType', pattern);


But I would like to build a pattern of regular expression. I have a check menu. According the checked box, I filter my JSonview and so I would like to generate dynamic pattern.

How can I build ?
I have trouble because the pattern have not to be a string.



function nivLog() {

var retour='';
for (var i=0 ; i<menu3Items.length ; i++){
if (menu3Items[i].checked) {
if (retour == '')
retour = tabLog.indexOf(menu3Items[i].text);
else
retour=retour|tabLog.indexOf(menu3Items[i].text);
}
return retour;
}

Animal
25 Apr 2008, 4:17 AM
Google the Javascript RegExp object.

caam
25 Apr 2008, 6:28 AM
Oki, thanks. I finally found.

So it is :


view.filter('MType',new RegExp("["+nivLog()+"]","i"));