There is a string that looks like
Some text tag, tag, scope = some scope, scope2
It is necessary to break this text into a string and an array of the form {Key,Value} where Key is the value that goes before = , and Value is a comma separated list. That is, the result should be:
queryText = "Some text" parameters = { [Key:tag; Value:Tag for this text], [Key:tag; Value:second tag], [Key:scope; Value:some scope], [Key:scope; Value:some scope2] } I did this:
var query = queryString.val().trim().split(" "); var queryText = query[0]; if(query.length > 1) { var itm = 1; var currScope = ""; for(itm; itm < query.length; itm ++) { if(query[itm].indexOf("=") > -1) { var filterVal = query[itm].split("="); currScope = filterVal[0]; var keys = filterVal[1].split(","); for(var k in keys) { if(keys[k]) { this.parameters.push({ Key: currScope, Value: keys[k] }); } } } else { if(currScope) { this.parameters.push({ Key: currScope, Value: query[itm]}); } } } } But such an implementation only works if in the queryString all phrases without phrases, that is, one phrase, without spaces.
How to expand the implementation correctly?
keycan't include spaces? - Grundy