【问题标题】:why does ui-select allow me to enter text?为什么 ui-select 允许我输入文本?
【发布时间】:2015-12-24 00:09:56
【问题描述】:

为什么 ui-select 允许我输入文本,这是预期的功能还是我破坏了它?可以关掉吗?

链接到 ui-select https://github.com/angular-ui/ui-select

【问题讨论】:

  • 你能发布你的代码吗?

标签: angularjs ui-select


【解决方案1】:

要回答您的问题,它允许您输入文本,因为它应该过滤下拉列表中的选项以匹配您提供的文本。

但是,目前看来这对您不起作用(从屏幕截图中),因此您似乎遇到了问题...

如果您转到问题中的链接 (https://github.com/angular-ui/ui-select) 并单击“演示”,您可以看到正在执行的过滤。

【讨论】:

    【解决方案2】:

    我不太懂英语。但我尝试使用 ajax man 方法。 像这样的

    var yourFuction = function (queryParams) {
        return YourRequest('/requestName?name=' + queryParams.data).then(queryParams.success);
    };
    
    $scope.modelToEdit = $("#modelData").data("source");
    
    $scope.searchClient = {
        multiple: false,
        allowClear: true,   
        initSelection: function(element, callback) {
        },          
        ajax: { 
            dataType: 'json',
            type: 'GET',
            data: function (term, page) {
                return term
            },
            transport: yourFuction,
            results: function (data, page) {
                return {
                    results: data.data
                };
            }
        },
        formatResult: function ( item ) {
            return item.name;
        },
        formatSelection: function(item) {
            return item.name;
        }
    };
    

    您的功能是您的后端请求。 运输是你的职责。 results 是后端发送给您的 JSON。您可以在退货前更改您的退货{ 结果:data.data };

    格式就是您输入的内容。示例:如果您需要显示 ID,则您的代码需要返回“item.id”。如果您需要显示任何数字,您的代码希望成为“item.number”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      • 1970-01-01
      • 2017-09-02
      相关资源
      最近更新 更多