在运行时获取两个属性并在字符串中组合这两个属性(orderby orderdirection)

Get two properties at runtime and make combination of those two properties in string (orderby orderdirection)

我在小部件中有两个属性“orderby”和“orderdirection”。 在运行时我可以调整这些属性检查片段:

我想在其余 api 查询中设置这些属性。 例如:Query = "/_api/web/lists/getbytitle('" + listname + "')/items?&"$select=ID,Title,Date&$orderby=标题 desc,日期 asc"

以上值是硬编码的,但我想在运行时更改这些值。当我只想更新一个值 "Title desc" 时,这很容易,但我想在运行时设置任意数量的列。

我的方法:先将字符串 orderby.Split(",") 溢出,然后用“orderby orderdirection, orderby orderdirection,orderby orderdirection”。 我只是想检查一下我是否可以在这里尝试其他方法。请在这里提出您的建议。谢谢。

一个解决方案:

    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);