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 :
JavaScript
x
12
12
1
var orderby = "Title,Date,Other";
2
var orderdirection = "desc,asc,asc";
3
4
var ar0 = orderby.split(",");
5
var ar1 = orderdirection.split(",");
6
var res=[];
7
for(let i = 0; i < ar0.length; i++){
8
res.push(ar0[i] + ' ' + ar1[i]);
9
}
10
11
var result = res.join(",");
12
console.log(result);