0

我有一个 api 端点,它将这些设置返回给客户端 HTML/JS,通过普通的 XML 请求或承诺或异步/等待来检索这些数据。

return new JsonResult(
                new List<object>()
                {
                    new { id = 1, size = "big", order = 6},
                    new { id = 2, size = "small", order = 4},
                    new { id = 3, size = "medium", order = 2},
                    new { id = 4, size = "small", order = 5},
                    new { id = 5, size = "small", order = 8, chips= new { }},
                    new { id = 6, size = "small", order = 7},
                    new { id = 7, size = "big", order = 1, chips= new { }},
                    new { id = 8, size = "small", order = 3},
                    new { id = 10, size = "big", order = 9},
                    new { id = 20, size = "big", order = 10}
                });

但是出现了一个新要求,需要我将这些设置保存到一个类中,并将它们的值保存到一个配置文件中,这样我们就不需要在每次添加新设置时都重新构建。
这是我做的课:

 public class Settings
    {
        public int Id { get;}
        public string Size { get;}
        public int Order { get;}
        public int[] Arrays { get;}
    }

我一直在研究创建配置文件并调用它们。我只是不知道如何将这些值保存到 api 中的配置文件中,以便可以在客户端中调用它,如下所示:

const getDataByPromise = function (method, url) {
  return new Promise(function (resolve, reject) {
    const xhr = new XMLHttpRequest();
    xhr.open(method, url);
    xhr.onload = function () {
      if (successfulHttpResponse(this.status)) {
        resolve(xhr.response);
        document.getElementById("promise").textContent = xhr.responseText;
      } else {
        reject({
          status: this.status,
          statusText: xhr.statusText,
        });
      }
    };
    xhr.onerror = function () {
      reject({
        status: this.status,
        statusText: xhr.statusText,
      });
    };
    xhr.send();
  });
};

你认为我应该如何实施这个

4

0 回答 0