I have two properties “orderby” and “orderdirection” in widget.
In runtime I can adjust those properties check snip :

I want to set these properties in my rest api query. eg: Query = “/_api/web/lists/getbytitle(‘” + listname + “‘)/items?&”$select=ID,Title,Date&$orderby=Title desc,Date asc“
Above values are hardcoded but I want to change those values in runtime. When I want to update just one value “Title desc”, its easy but I want to set any number of columns at runtime.My approach : Spilt the string first orderby.Split(“,”) and then make one string with both combination of “orderby orderdirection,orderby orderdirection,orderby orderdirection“. I just wanted to check if any other approach I can try here. Please suggest your suggestion here. Thank you .
Advertisement
Answer
a solution :
var orderby = "Title,Date,Other";
var orderdirection = "desc,asc,asc";
var ar0 = orderby.split(",");
var ar1 = orderdirection.split(",");
var res=[];
for(let i = 0; i < ar0.length; i++){
res.push(ar0[i] + ' ' + ar1[i]);
}
var result = res.join(",");
console.log(result);