我有一个带有Quickbase recordID和fieldID的函数,并删除与该字段关联的任何文件。一,功能:
function deleteFiles(recid,fldid) {
var apptoken = "xxxxxxxxxxxxxxxxxxxxxxxxx";
$.ajaxSetup({data: {apptoken: apptoken}});
var dbid = "xxxxxxxxx";
var promise = $.post(dbid, {
act: "API_EditRecord",
rid: recid,
_fid_NN: "",
delfile_fid_NN: "1"
});
$.when(promise).then(function(xml){
console.dirxml(xml);
});
}
其中“NN”需要等于传递的fieldID(fldid)。我已经尝试将fldid连接到这两个关键名称,但这不起作用。我已经看到很多类似的问题,建议创建对象等,但这些也不适用于我的情况。所以问题是,如何动态更改这些键名,以便QB满意并删除文件?谢谢!
答案 0 :(得分:0)
尝试以下方法:
function deleteFiles(recid,fldid) {
var apptoken = "xxxxxxxxxxxxxxxxxxxxxxxxx";
$.ajaxSetup({data: {apptoken: apptoken}});
var dbid = "xxxxxxxxx";
var payload = {
act: "API_EditRecord",
rid: recid
};
payload['_fid_' + fldid] = '';
payload['delfile_fid_' + fldid] = '1';
var promise = $.post(dbid, payload);
$.when(promise).then(function(xml){
console.dirxml(xml);
});
}
答案 1 :(得分:0)
您也可以使用以下ES6功能执行此操作。
function deleteFiles(recid, fldid) {
var apptoken = "xxxxxxxxxxxxxxxxxxxxxxxxx";
$.ajaxSetup({
data: {
apptoken: apptoken
}
});
var dbid = "xxxxxxxxx";
var promise = $.post(dbid, {
act: "API_EditRecord",
rid: recid,
['_fid_' + fldid]: "",
['delfile_fid_' + fldid]: "1"
});
$.when(promise).then(function(xml) {
console.dirxml(xml);
});
}