tabulator.js:带有 valuelookup 和自定义 ajax-get 的列表

问题描述 投票:0回答:2

我正在尝试在 tabulator.js 的列中使用列表。 这个列表的来源应该是一个自定义的ajax请求。
据我了解,我必须回报一个承诺。 但这不起作用。 http 请求已完成,但我在下拉列表中看到的只是废话。 有人可以给我提示吗?

{title:"Name", field:"name", editor:"list", editorParams:{
    valuesLookup:function(cell, filterTerm){
          res =  $.ajax({
              url: "/api/v1/networks",
              type: "GET",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
          });
          return res.promise();
    }
}},

如果我使用实现的“valuesURL”,它工作正常,但我以后不能使用它。

javascript tabulator
2个回答
0
投票

我自己找到了以下解决方案:

{title:"Name", field:"name1", editor:"list", editorParams:{
valuesLookup:function(cell, filterTerm){
  return new Promise(function(resolve, reject){
    $.ajax({
        url: "/api/v1/networks",
        success: function(data){
            resolve(data);
        },
        error: function(error){
            reject(error);
        },
    })
  })
}

}},


0
投票

这并不是一个真正的答案,而是一个问题:你会得到什么回报?带有键/值对的列表或 json?

© www.soinside.com 2019 - 2024. All rights reserved.