搜索数组返回部分匹配(Search an array return partial matches)
我需要为一个字符串搜索关联数组的值,但只能搜索字符串示例的开始部分:
var stack = ['aba', 'abcd', 'ab', 'da', 'da'];
搜索堆栈中的值
a
会返回['abc, 'abcd', 'ab']
,对于b
只会返回b,而搜索'd'会返回[da', 'da']
...任何方式来做到这一点?我试图做一个自动完成选择框,但它的自定义,所以我需要修改文本事件和搜索我的项目数组以获得第一个匹配的索引,而用户正在键入。
I need to search an associative array's values for a string, but only the beginning of the string example:
var stack = ['aba', 'abcd', 'ab', 'da', 'da'];
a search on stack for the value
a
would return['abc, 'abcd', 'ab']
, and forb
would just return b while a search for 'd' would return[da', 'da']
...any way to do that?Im trying to do like an autocomplete select box, but its custom so i need to moditor text events and search my array of items to get the index of the first match while the user is typing.
原文:https://stackoverflow.com/questions/5440275
最满意答案
由于这已经证明是不可能的,我最终将第二个动态生成的表单浮动到顶部,Opacity设置为0.01。 然后,我使用主窗体上的Resize和LocationChanged事件来调整大小并根据需要移动叠加窗体。 然后我只需要根据需要处理叠加表单点击事件。
public MainFrom() { InitializeComponent(); f = new Form(); f.Size = panel1.Size; f.FormBorderStyle = FormBorderStyle.None; f.BackColor = Color.Black; f.Opacity = 0.01; f.ShowInTaskbar = false; f.Show(this); f.Click += new System.EventHandler(this.UserClicked); }
然后,此代码调整叠加表单的大小以考虑主窗体边框:
private void SetLocation() { // These next 2 lines calculate the width of the border // and the title bar and then use these to off set the floating // forms location correctly. int xOffset = (this.Width - this.ClientSize.Width) / 2; int yOffset= this.Height - this.ClientSize.Height - xOffset; int x = this.Location.X + panel1.Location.X + xOffset; int y = this.Location.Y + panel1.Location.Y + yOffset; f.Location = new Point(x, y); }
根据MoMa工具,这是100%单声道兼容,代码按照预期编译在MonoDevelop中。 但是,如果我运行这个,我看到一个空引用异常,我没有在加载的MS .NET中看到,这可能是可修复的,但我还没有调查。
As this has turned out to be impossible I ended up floating a 2nd dynamically generated form over the top with Opacity set to 0.01. I then used the Resize and LocationChanged events on the main form to resize and move the overlay form as required. I then just needed to handle the overlay forms click event to do as I needed.
public MainFrom() { InitializeComponent(); f = new Form(); f.Size = panel1.Size; f.FormBorderStyle = FormBorderStyle.None; f.BackColor = Color.Black; f.Opacity = 0.01; f.ShowInTaskbar = false; f.Show(this); f.Click += new System.EventHandler(this.UserClicked); }
This code then resizes the overlay form to account for the main forms border:
private void SetLocation() { // These next 2 lines calculate the width of the border // and the title bar and then use these to off set the floating // forms location correctly. int xOffset = (this.Width - this.ClientSize.Width) / 2; int yOffset= this.Height - this.ClientSize.Height - xOffset; int x = this.Location.X + panel1.Location.X + xOffset; int y = this.Location.Y + panel1.Location.Y + yOffset; f.Location = new Point(x, y); }
According to the MoMa tool this is 100% mono compatible and the code compiles in MonoDevelop as expected. However if I run this I am seeing a null reference exception I do not see in MS .NET on load, this might be fixable but I am yet to look into this.
相关问答
更多-
对于vim: highlight Normal ctermbg=Black highlight NonText ctermbg=Black 你的colorschema很可能没有设置ctermbg。 将“黑色”替换为所需的背景颜色。 For vim: highlight Normal ctermbg=Black highlight NonText ctermbg=Black Your colorschema most likely does not set ctermbg. Replace "Black" ...
-
由于这已经证明是不可能的,我最终将第二个动态生成的表单浮动到顶部,Opacity设置为0.01。 然后,我使用主窗体上的Resize和LocationChanged事件来调整大小并根据需要移动叠加窗体。 然后我只需要根据需要处理叠加表单点击事件。 public MainFrom() { InitializeComponent(); f = new Form(); f.Size = panel1.Size; f.FormBorderSt ...
-
CSS背景透明度?(css background transparency?)[2023-10-21]
更改id =“page”的div的背景颜色 例如 #page{ background-color: rgba(185, 178, 178, 0.71); } 根据需要更改颜色。 希望这能解决你的问题 change the background color of the div with id="page" for example #page{ background-color: rgba(185, 178, 178, 0.71); } change the color as needed. Hope t ... -
感谢Hans Passant指出我正确的方向。 我最终创建了一个线程,检查鼠标是否每隔50ms处于边界内。 public Detached(PictureBox map) { Thread HoverCheck = new Thread(() => { while (true) { if (this.Bounds.Contains(Cursor.Position)) { Toggl ...
-
这是一个简单的技巧。 添加同一帧的子视图并更改为alpha。 UIView *popupView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)]; UIView *bgView = [[UIView alloc] initWithFrame:popupView.frame]; UIColor * bgColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_bg. ...
-
如果我理解正确,你想在父div打开一个窗口/洞。 据我所知,你不能这样做,因为div在文本框后面,并且你应用它们的任何透明度都会导致div显示在框中,而不是div后面的内容。 也许,而不是背景颜色,你可以使div背景成为一个PNG图像,其中两个透明孔与文本框重合,但这是一种解决方法,与你的一样。 If I understand correctly, you want to open a window/hole in the parent div. As far as I know, you can't do ...
-
Android - 背景透明度也设置Paint对象的透明度(Android - Background transparency sets also transparency on Paint object)[2022-08-07]
我在这里找到了解决方案 @Override protected void dispatchDraw(Canvas canvas) { // draw here if you want to draw behind children super.dispatchDraw(canvas); // draw here if you want to draw over children } I found the solution here @Override protected void ... -
您可以设置imageView的属性: imgView.contentMode = UIViewContentModeScaleToFill; imgView.clipsToBounds = YES; 在这种情况下,imageviews将定义它们之间没有任何空格,尽管可以更改宽高比如果UIViewContentModeScaleAspectFill不符合您的要求,请尝试UIViewContentModeScaleAspectFill You may set the imageView's propertie ...
-
目前,CSS不允许更改背景图像的alpha值。 如果您希望解决此问题,有几种不同的选择: 只需将背景图像保存为适当不透明度的透明png即可。 使背景图像成为相对定位的父容器中自己绝对定位的元素。 。some text
-
使用纯css是不可能的,因为你需要使绿色div也是透明的,这显然不是。 解决方法是让您的小方块与您想要的背景相同,然后使用background-position将图像移动到您想要的位置 .blue { width: 200px; height: 200px; } .blue, .same_as_blue { background: url(http://lorempixel.com/200/200/) left top no-repeat; } .green ...