首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ektron中的模板化控件

ektron中的模板化控件
EN

Stack Overflow用户
提问于 2013-10-21 15:10:28
回答 1查看 538关注 0票数 0

我已经尝试使用分类树检索分类列表,在编辑中我选择分类并获取TaxonomyID,通过使用taxonomyID我想使用模板控件显示使用分类过滤器的数据。我无法检索数据。

代码语言:javascript
复制
    <asp:View ID="View" runat="server">          

    <asp:Label ID="lblID" runat="server"></asp:Label>            
    <CMS:Directory CssClass="taxList" ID="TaxonomySummary1" EnableAjax="true" runat="server"
                EnablePaging="false"  />

          <ektron:ContentModelSource ID="cntModelSourcs" runat="server" OrderByField="DateCreated" 
    OrderByDirection="Descending">    


   <TaxonomyFilters>
        <ektron:ContentTaxonomyFilter Operator="Contains"  ID="taxFilter" runat="server" />

    </TaxonomyFilters>

     <ContentFilters>   
       <ektron:ContentFilter Field="Id" Operator="EqualTo" Value=""   />
    </ContentFilters>
</ektron:ContentModelSource>

<ektron:ContentView ID="ContentView1" runat="server"  ModelSourceID="cntModelSourcs"  
    EktronCustomTemplate="Ektron_ContentList_Template" >

</ektron:ContentView>
    </asp:View>

enter code here _edit“class="TSWidget">

代码语言:javascript
复制
    <div class="ByTaxonomy TSTabPanel">
                    <div style="height: 150px; overflow: auto;">
                        <UC:TaxonomyTree ID="TaxonomyTree1" runat="server" />

                    </div>
                    <hr />

                </div>
    <div class="ByProperty TSTabPanel">
                    <table style="width: auto;">
                        <tr>
                            <td class="label">
                                <%=m_refMsg.GetMessage("lbl taxonomy id:")%>

                            </td>
                            <td>
                                <asp:TextBox ID="taxonomyid" CssClass="folderid" runat="server" Style="width: auto;"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <%=m_refMsg.GetMessage("lbl taxonomy path:")%>
                            </td>
                            <td>
                                <asp:Label ID="taxonomypath" CssClass="taxonomypath" runat="server"></asp:Label>
                              </td> 
                        </tr>                           
                    </table>
                </div>
    <div class="TSEditControls">
                    <asp:Button ID="CancelButton" CssClass="TSCancel" runat="server" Text="Cancel" OnClick="CancelButton_Click" />
                    <asp:Button ID="SaveButton" CssClass="TSSave" runat="server" OnClick="SaveButton_Click" Text="Save" />                       
                </div>
  </div>

</asp:View>

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ektron.Cms;
using Ektron.Cms.Widget;
using Ektron.Cms.Common;
using Ektron.Cms.API;
using Ektron.Cms.Organization;
using Ektron.Cms.Framework.Organization;
using System.Text;
using Ektron.Cms.Search.Expressions;
using Ektron.Cms.Search;
using Ektron.Cms.Framework;
public partial class widgets_Content_TaxonomyFilter : System.Web.UI.UserControl,IWidget
{
# region Properties
protected string appPath = "";
private Ektron.Cms.CommonApi _commonAPI = new CommonApi();
private long _taxonomyid;
public string TaxonomySelected = "selected";
public string PropertySelected = "selected";
public string m_strTaxonomyPath = "/";
private string _taxonomypath;

[WidgetDataMember(0)]
public long TaxonomyId { get { return _taxonomyid; } set { _taxonomyid = value; } }

[WidgetDataMember("")]
public string TaxonomyPaths { get { return _taxonomypath; } set { 
_taxonomypath         =       value; } }    private IWidgetHost _host;    
protected ContentAPI m_refContentApi = new ContentAPI();
protected EkMessageHelper m_refMsg;
#endregion

# region Page Load
protected void Page_Load(object sender, EventArgs e)
{
    taxFilter.Value = TaxonomyId.ToString();
    ContentView1.DataBind();
}
#endregion

#region Page Init
protected void Page_Init(object sender, EventArgs e)
{
    m_refMsg = m_refContentApi.EkMsgRef;
    CancelButton.Text = m_refMsg.GetMessage("btn cancel");
    SaveButton.Text = m_refMsg.GetMessage("btn save");
    _host = Ektron.Cms.Widget.WidgetHost.GetHost(this);
    _host.Title = "Templated Control";
    _host.Edit += new EditDelegate(EditEvent);
    _host.Maximize += new MaximizeDelegate(delegate() { Visible = true; });
    _host.Minimize += new MinimizeDelegate(delegate() { Visible = false; });
    _host.Create += new CreateDelegate(delegate() { EditEvent(""); });
    _host.ExpandOptions = Expandable.ExpandOnEdit;
    appPath = _commonAPI.AppPath;
    Load += new EventHandler(delegate(object PreRenderSender, EventArgs Evt) { if 
    (ViewSet.GetActiveView() != Edit) SetTaxonomySummary(); });
    ViewSet.SetActiveView(View);
    }

protected void SetTaxonomySummary()
{
    if (TaxonomyId > 0)
    {
        lblID.Text = Convert.ToString(taxFilter.Value);

    }

}
#endregion

#region EditEvent
void EditEvent(string settings)
{
    try
    {
        string sitepath = _commonAPI.SitePath;
        string webserviceURL = sitepath + "widgets/taxonomysummary/TSHandler.ashx";
        JS.RegisterJSInclude(this, JS.ManagedScript.EktronJS);
        Ektron.Cms.API.JS.RegisterJSInclude(this, 
 Ektron.Cms.API.JS.ManagedScript.EktronJQueryClueTipJS);
        JS.RegisterJSInclude(this, JS.ManagedScript.EktronScrollToJS);
        JS.RegisterJSInclude(this, sitepath + "widgets/taxonomysummary/behavior.js", 
 "TaxonomySummaryWidgetBehaviorJS");

        if (TaxonomyId > 0)
        {
            TaxonomySelected = "";
            JS.RegisterJSBlock(this, "Ektron.PFWidgets.TaxonomySummary.webserviceURL = 
\"" + webserviceURL + "\"; 
 Ektron.PFWidgets.TaxonomySummary.setupAll();
 Ektron.PFWidgets.TaxonomySummary.SetTabs.init()
 ; ", "EktronPFWidgetsTSInit");
        }
        else
        {
            PropertySelected = "";
            JS.RegisterJSBlock(this, "Ektron.PFWidgets.TaxonomySummary.webserviceURL = 
  \"" + webserviceURL + "\"; 
 Ektron.PFWidgets.TaxonomySummary.setupAll(); ", "EktronPFWidgetsTSInit");
        }

        Css.RegisterCss(this, sitepath + "widgets/taxonomysummary/TSStyle.css",  
  "TSWidgetCSS");
        ViewSet.SetActiveView(Edit);
        //set taxonomy path
        Ektron.Cms.API.Content.Taxonomy _apiTaxonomy = new  
        Ektron.Cms.API.Content.Taxonomy();
        Ektron.Cms.TaxonomyRequest taxRequest = new Ektron.Cms.TaxonomyRequest();
        taxRequest.TaxonomyId = TaxonomyId;
        taxRequest.IncludeItems = false;
        taxRequest.TaxonomyLanguage = _apiTaxonomy.ContentLanguage;
        Ektron.Cms.TaxonomyData taxData = _apiTaxonomy.LoadTaxonomy(ref taxRequest);

        if (!(taxData == null || string.IsNullOrEmpty(taxData.Path)))
        {
            taxonomypath.Text = taxData.Path;
            m_strTaxonomyPath = taxData.Path;
        }
        else
        {
            m_strTaxonomyPath = "";
        }
    }
    catch (Exception e)
    {
        ViewSet.SetActiveView(View);
    }
}
#endregion

#region Button Events
protected void CancelButton_Click(object sender, EventArgs e)
{
    ViewSet.SetActiveView(View);

}
protected void SaveButton_Click(object sender, EventArgs e)
{
    int taxID = Convert.ToInt32(taxonomyid.Text);
    TaxonomyId = taxID;
    taxFilter.Value = TaxonomyId.ToString();

    SetTaxonomySummary();
    _host.SaveWidgetDataMembers();
    ViewSet.SetActiveView(View);

}

#endregion

public EventArgs e { get; set; }

}

EN

回答 1

Stack Overflow用户

发布于 2013-10-29 11:09:39

如果我正确理解了您的问题,那么您有分类法id,并且希望显示该分类法中的所有内容。如果这不是你想要的,那么请澄清你的问题,我将尽我所能提供帮助。

我发现,小部件带来的额外负担有时会使测试正确的API和服务器控件用法变得困难。因此,我建议从一个简单的ASPX页面开始。

代码语言:javascript
复制
<ektron:ContentModelSource ID="contentModelSource" runat="server">
</ektron:ContentModelSource>

<ektron:ContentView ID="ContentView1" runat="server"  ModelSourceID="contentModelSource" EktronCustomTemplate="Ektron_ContentList_Template">
</ektron:ContentView>

通常,您将找到的模板化服务器控件的示例显示了用于设置筛选器的声明性语法,您可以将它们直接放入ASPX标记中-就在ContentModelSource控件内。类似于:

代码语言:javascript
复制
<TaxonomyFilters> 
    <ektron:ContentTaxonomyFilter Field="Id" Operator="EqualTo" Value="208" />
</TaxonomyFilters>

(更多示例是和。)

但是对于听起来像是你想要完成的事情,你需要通过代码定义过滤器。这段代码就是这样做的:

代码语言:javascript
复制
protected long TaxonomyId
{
    get
    {
        long id;
        long.TryParse(Request.QueryString["id"], out id);
        return id;
    }
}

protected bool IsRecursive
{
    get
    {
        bool recursive;
        bool.TryParse(Request.QueryString["recursive"], out recursive);
        return recursive;
    }
}

protected void Page_Init(object sender, EventArgs e)
{
    if (TaxonomyId > 0)
    {
        if (IsRecursive)
        {
            var tm = new TaxonomyManager();
            var td = tm.GetItem(TaxonomyId);
            if (td != null)
            {
                var pathFilter = new ContentTaxonomyFilter();
                pathFilter.Field = ContentTaxonomyProperty.Path;
                pathFilter.Operator = CriteriaFilterOperator.StartsWith;
                pathFilter.Value = td.Path;

                contentModelSource.TaxonomyFilters.Add(pathFilter);
            }
        }
        else
        {
            var filter = new ContentTaxonomyFilter();
            filter.Field = ContentTaxonomyProperty.Id;
            filter.Value = TaxonomyId.ToString();
            filter.Operator = CriteriaFilterOperator.EqualTo;

            contentModelSource.TaxonomyFilters.Add(filter);                
        }
    }
}

需要注意的几件事:

  • TaxonomyId是一个属性。我这样做是为了便于在这个简单的ASPX页面和自定义小部件之间进行比较,在这个小部件中,您的属性将使用WidgetDataMember属性进行装饰。
  • 代码位于Page_Init事件处理程序中。这一点很重要。在页面的生命周期中,Page_Load为时已晚。我假设这在小部件的上下文中也是正确的。当IsRecursive == true不一定优化时,
  • 我的代码。您可以通过turning on caching in the FrameworkAPI获得合理的性能,但是调用api来获取taxonomyData,然后使用它来为内容设置过滤器的想法似乎有点不靠谱。理想情况下,ContentTaxonomyFilter应该有一个“递归”属性。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19488218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档