0

我有一个代码,它使用它的 api 在 Skydrive 中创建新文件夹。它实际上工作。但它总是创建具有相同名称的文件夹。因为文件夹的名称是硬编码的。

我的问题是如何将文本框绑定到 API 调用,以便它将用户指定的文件夹名称传递给 API

这是创建文件夹的代码:

  <script src="//js.live.net/v5.0/wl.js" type="text/javascript" language="javascript"></script>
  <script type="text/javascript" language="javascript">
      function createFolder_onClick() {
          WL.login({
              scope: "wl.skydrive_update"
          }).then(
          function (response) {
        WL.api({
            path: "me/skydrive",
            method: "POST",
            body: {
                "name": "This is a new folder",
                "description": "A new folder"
            }
        }).then(
            function (response) {
                document.getElementById("infoArea2").innerText =
                    "Created folder. Name: " + response.name + ", ID: " + response.id;
            },
            function (responseFailed) {
                document.getElementById("infoArea2").innerText =
                    "Error calling API: " + responseFailed.error.message;
            }
        );
    },
    function (responseFailed) {
        document.getElementById("infoArea2").innerText =
            "Error signing in: " + responseFailed.error_description;
    }
      );
      }
  </script>
4

1 回答 1

0

您需要用文本框的内容替换文件夹的硬编码名称。如果代码中带有文件夹名称的文本框的名称是 txtFolderName,那么这样的事情应该可以工作:

 <script src="//js.live.net/v5.0/wl.js" type="text/javascript" language="javascript">     </script>
  <script type="text/javascript" language="javascript">
      function createFolder_onClick() {
          WL.login({
              scope: "wl.skydrive_update"
          }).then(
          function (response) {
        WL.api({
            path: "me/skydrive",
            method: "POST",
            body: {
            "name": document.getElementById("txtFolderName").value,
            "description": "A new folder"
           }
        }).then(
            function (response) {
                document.getElementById("infoArea2").innerText =
                    "Created folder. Name: " + response.name + ", ID: " + response.id;
            },
            function (responseFailed) {
                 document.getElementById("infoArea2").innerText =
                    "Error calling API: " + responseFailed.error.message;
            }
        );
    },
    function (responseFailed) {
        document.getElementById("infoArea2").innerText =
            "Error signing in: " + responseFailed.error_description;
    }
      );
      }
  </script>
于 2013-05-13T18:46:11.493 回答