0

我有一个函数,它采用 Quickbase 记录 ID 和 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 满意并且文件被删除?谢谢!

4

2 回答 2

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);
    });
}
于 2016-11-11T20:47:44.453 回答
0

You could also do this using ES6 features as below.

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

于 2016-11-11T20:57:24.317 回答