简体   繁体   English

AngularJS材质-md-autocomplete隐藏了部分建议

[英]AngularJS Material - md-autocomplete hides part of the suggestion

I have a problem with the md-autocomplete of AngularJS Material. 我对AngularJS材质的md-autocomplete有问题。 Actually I'm having trouble with md-virtual-repeater-container, which is used by the md-autocomplete to render the dropdown list with suggestions. 实际上,我在使用md-virtual-repeater-container时遇到麻烦,它由md-autocomplete用于呈现带有建议的下拉列表。

This element doesn't show the full content of the suggestion text that is displayed in the dropdown list. 此元素未显示下拉列表中显示的建议文本的全部内容。

Here is a screenshot: 这是屏幕截图:

在此处输入图片说明

Here it shows the suggestion, but it is butchered and appended with "...". 在这里显示了建议,但在其中添加了“ ...”。

I've tried using md-menu-class property on my md-autocomplete element but this doesn't work because it is only giving style to an element inside the md-virtual-container, but it doesn't do anything to grow the md-virtual-container. 我已经尝试过在md-autocomplete元素上使用md-menu-class属性,但这是行不通的,因为它只是为md-virtual-container内部的元素赋予样式,但是它并没有做任何事情来增加md-virtual-container。

The solution I need is to make somehow to grow the md-virtual-container to fit the suggestions displayed by the md-autocomplete. 我需要的解决方案是做出某种方式来增长md-virtual-container,以适应md-autocomplete显示的建议。

Here is a codepen to play with: https://codepen.io/aee/pen/ejgxmY 这是一个可使用的codepen: https ://codepen.io/aee/pen/ejgxmY

And this is the code on codepen: 这是codepen上的代码:

 (function () { 'use strict'; angular .module('MyApp') .controller('CustomInputDemoCtrl', DemoCtrl); function DemoCtrl ($timeout, $q) { var self = this; self.readonly = false; self.selectedItem = null; self.searchText = null; self.selectedVegetables = []; self.numberChips = []; self.numberChips2 = []; self.numberBuffer = ''; self.itemList = [ {t:"aaaa"}, {t:"bbbbbbbb"}, {t:"cccccccccccccccc"}, {t:"dddddddddddddddddddddddddddd"}, {t:"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"}, {t:"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, {t:"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"}, {t:"dddddddddddddddddddddddddddd"}, {t:"cccccccccccccccc"}, {t:"bbbbbbbb"}, ] } })(); 
 .larger-width { with: 1000px; } 
 <div ng-controller="CustomInputDemoCtrl as ctrl" layout="column" class="chipsdemoCustomInputs" ng-app="MyApp"> <md-content class="md-padding" layout="column" style="background-color: lightgray; width: 250px"> <md-autocomplete md-selected-item="ctrl.selectedItem" md-search-text="ctrl.searchText" md-items="item in ctrl.itemList" md-item-text="item.t" placeholder="Search" md-floating-label="Select One"> <md-item-template> <span md-highlight-text="ctrl.searchText" md-highlight-flags="^i"> {{item.t}} </span> </md-item-template> <md-not-found> <span>No dataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.</span> </md-not-found> </md-autocomplete> </md-content> </div> 

  1. Get longest element in autocomplete 获取最长的自动完成元素
  2. Scale md-autocomplete every time the autocomplete list is dispatched using this extremely helpful function: Calculate text width with JavaScript 每次使用此非常有用的功能调度自动完成列表时,缩放md-autocomplete: 使用JavaScript计算文本宽度
  3. Profit 利润

See also this proof-of-concept that scaling the width of md-autocomplete works ( https://codepen.io/cyniikal/pen/jpJjzB ) 另请参阅此概念证明,即缩放md-autocomplete的宽度有效( https://codepen.io/cyniikal/pen/jpJjzB

HTML 的HTML

<md-autocomplete 
         md-selected-item="ctrl.selectedItem" 
         md-search-text="ctrl.searchText" 
         md-items="item in ctrl.itemList" 
         md-item-text="item.t" 
         placeholder="Search"
         md-floating-label="Select One" id='it-works'>

CSS 的CSS

#it-works {
    width: 1000px;
}

md-content {
    overflow-x: hidden;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM