我有一个代码,可以使用它的api在Skydrive中创建新文件夹。它实际上工作。但它始终创建具有相同名称的文件夹。因为文件夹的名称是硬编码的。
我的问题是如何将textBox绑定到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>
答案 0 :(得分: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>