从自动完成方法中排除项目
我有以下代码,可以提取文本框自动完成扩展器中使用的项目列表:
return autocomplete.tblAutoCompletes
.Where(p => p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText))
.OrderBy(p => p.ACItem)
.Select(p => p.ACItem)
.Take(count)
.ToArray();
其中memberid 和locationid 是会话。
在此项目列表中,我可能希望根据用户偏好排除一些项目。该首选项也被存储为会话。
例如,我有下表:
ACItem ACColumn
aa Product
ab Product
ac Product
ad Status
ae Status
af Status
ag Category
ai Category
aj Category
如果我在文本框中输入“a”,则将显示所有产品 ACItems。
但是,可能存在一种情况,我不希望用户自动完成显示特定状态和/或产品。例如,我不希望用户看到状态“af”或类别“ai”。
当用户登录时,我将这些首选项存储为会话(即“DoNotDisplayaf”或“DoNotDisplayai”)。
如何修改我的原始方法,以便自动完成功能考虑这些例外情况?
抱歉,我的问题/例子有点模糊。
感谢您收到的任何帮助。
I have the following code that pulls off a list of items used in an text box autocomplete extender:
return autocomplete.tblAutoCompletes
.Where(p => p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText))
.OrderBy(p => p.ACItem)
.Select(p => p.ACItem)
.Take(count)
.ToArray();
Where memberid and locationid are sessions.
Within this list of items, I have some that I may wish to exclude depending upon user preferences. This preference also being stored as a session.
So for example I have the following table:
ACItem ACColumn
aa Product
ab Product
ac Product
ad Status
ae Status
af Status
ag Category
ai Category
aj Category
The if I typed in "a" into my text box, all products ACItems would be displayed.
However, there may be a scenario whereby I don't want a users autocomplete to display a certain status and or product. For example, I don't want the user to see the status "af" or category "ai".
I have these preferences stored as a session when the user logs in (i.e. "DoNotDisplayaf" or "DoNotDisplayai")
How do I amend my original method so that the autocomplete takes these exceptions into account?
Apologies for being thick and if my question/example is a little hazy.
Thank you for any help received.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太确定我是否遵循,但考虑到您不希望显示所有产品类别,您是否能够在 linq 查询的Where 子句中过滤掉这些产品类别?
ShouldBeDisplayed 是一个函数,用于检查给定项目与会话状态中的条件,以确定是否应该显示它们。
Not quite sure I follow, but given you do not want all product categories to be shown, wouldn't you be able to filter these out in the Where clause of your linq query?
ShouldBeDisplayed is a function that checks the given item with the conditions in your session state to tell if they should be shown or not.