如何在 Mule 连接器中创建具有动态值的下拉列表

How to create drop-down list with dynamic values in Mule connector

我知道有一种使用枚举创建下拉列表的方法(这里也提到了 how do i add a drop down list item in a mule connector?),但在那种情况下,枚举已经预定义,你知道这些值。 如果我不知道前面的值怎么办,例如下拉列表需要从 API 调用中获取值。我怎么能这样做?

您可以使用 DataSense 来实现它,但要采用一种骇人听闻的方式,因为您将只使用密钥并为所有密钥检索相同的实体。

如果您不熟悉,我建议您阅读 DataSense Docs

示例:

@MetadataCategory
public class DropDownCategory(){

    // this method output will be displayed as a dropdown list
    @MetaDataKeyRetriever
    public List<MetaDataKey> getMetaDataKeys() throws Exception {
        List<MetaDataKey> keys = new ArrayList<>();
        // Fill your list with the data of the ap
        // new DefaultMetaDataKey(id, value));
        return keys;
    }

    @MetaDataRetriever
    public MetaData getMetaData(MetaDataKey key) throws Exception {
        // here you will retrieve the same entity for all the keys (or not, depending what you want to implement)
        return new DefaultMetaData(...);
    }

} 

最后,您需要使用 @MetaDataScope(DropDownCategory.class) 注释您的处理器,并使用 @MetaDataKeyParam

表示您希望表示为下拉列表的参数

希望对您有所帮助