从自动完成方法中排除项目

发布于 2024-09-13 21:03:51 字数 864 浏览 2 评论 0原文

我有以下代码,可以提取文本框自动完成扩展器中使用的项目列表:

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉目亦如画i 2024-09-20 21:03:51

不太确定我是否遵循,但考虑到您不希望显示所有产品类别,您是否能够在 linq 查询的Where 子句中过滤掉这些产品类别?

.Where(p => p.MemberId == memberid 
     && p.LocationId == locationid 
     && p.ACItem.Contains(prefixText) 
     && shouldBeDisplayed(p)) 

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?

.Where(p => p.MemberId == memberid 
     && p.LocationId == locationid 
     && p.ACItem.Contains(prefixText) 
     && shouldBeDisplayed(p)) 

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文