Orchard 基于过滤的下拉选择创建投影或搜索 [英] Orchard Create Projection or Search Based on Filtered Dropdown Selections

查看:39
本文介绍了Orchard 基于过滤的下拉选择创建投影或搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的功能,我想是,我正尝试将它添加到我的 Orchard (1.6) 站点,但是我找不到任何关于如何添加的教程或说明.我有一个名为Office"的自定义类型,每个办公室都有一个名为State"的自定义字段,指示办公室所处的状态.我实际上将我的办公室设计为代码中的自定义部分,其中包含特定属性,例如 State,但我认为"这就像我通过管理界面将状态添加为 Office 内容部分的字段一样.

I have, what I think is, a simple feature that I am trying to add to my Orchard (1.6) site, but I can't find any tutorials or instructions on how to do it. I have a custom type called "Office" and each office has a custom field called "State" indicating which state the office is in. I actually designed my Offices as a custom part in code with specific properties such as State on it, but I "think" it's the same as if I added the State through the Admin interface as a field on the Office content part.

现在,我可以创建一个基本投影来显示所有办公室,并使用一个简单的Office 类型内容"过滤器来显示所有办公室.但是,我现在想要做的是在页面顶部有一个下拉列表,上面写着过滤方式:[-SELECT STATE-]",其中包含所有 50 个州的列表.当用户选择一个状态时,页面应刷新并仅显示处于该状态的办公室.

Now, I can create a basic projection to show all the offices with a simple filter of "Content with type Office" to display all offices. However, what I want to do now is to have a drop down list at the top of the page that says "Filter by: [-SELECT STATE-]" with a list of all 50 states. When the user selects a state, the page should refresh and display just the offices in that state.

这就是我被卡住的地方.我应该通过代码执行此操作,还是可以通过管理 UI 执行此操作?如果通过代码,我应该在 Orchard.Search 模块之后对其进行建模(我尝试这样做,但我完全迷失了).如果我可以通过 UI 做到这一点,我是否使用投影?如果是这样,我是否必须创建 50 个单独的预测(每个州一个)?创建和维护这似乎非常耗时.

This is where I'm stuck. Should I do this through the code, or can I do this through the Admin UI? If through the code, should I model it after the Orchard.Search module (which I tried to do, but I am completely lost). If I can do it through the UI, do I use projections? If so, do I have to create 50 separate projections (one for each state)? That seems extremely time consuming to create and maintain.

非常感谢任何帮助!

仅供参考,该网站位于 http://ktowneric.com/listings/search(使用 Orchard) 与我正在寻找的非常相似,开发人员表示他使用了投影,但我似乎无法弄清楚他是如何做到的.

FYI, the site at http://ktowneric.com/listings/search (which uses Orchard) is very similar what I am looking for, and the developer stated he used projections, but I can't seem to figure out how he did it.

推荐答案

你绝对可以使用投影.如果您注意到在您引用的页面上使用搜索功能时,输入会形成查询字符串值.您可以使用令牌从查询字符串中获取值以在投影过滤器中使用.例如,如果您按照您的说明使用字段,那么您只需为该字段添加一个过滤器,并在值字段中使用 {Request.QueryString:State}.或者,将State"替换为您用于查询字符串值的任何键.

You can definitely use a projection. If you notice when you use the search function on the page you referenced, the inputs are formed into query string values. You can use tokens to grab the values from query strings to use in your projection filter. For example, if you're using fields as you stated, then you just add a filter for that field and in the value field use {Request.QueryString:State}. Or, replace "State" with whatever key you're using for the query string value.

这解决了您的投影问题.您将需要构建一个看起来像这样的搜索表单...

That solves your projection issue. You will need to build a search form that would look something like this...

<form action="/search-results" method="Get">
  <select name="State">
     <option value="OH">Ohio</option>
     ...all the states...
  </select>
  <input type="submit" value="Search" />
</form>

"/search-results" 可以是投影页面或任何存在投影小部件的内容.您可以将表单构建为可以放置在某处的小部件,或者出于测试目的,您可以将此 html 粘贴到 html 小部件中进行试用.

"/search-results" could be a projection page or any content that has the projection widget present. You could build the form as a widget that you can place somewhere, or for testing purposes, you could just paste this html into an html widget to try it out.

这篇关于Orchard 基于过滤的下拉选择创建投影或搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆