Bootstrap'崩溃'上课不附加问题

时间:2016-07-11 09:36:16

标签: javascript angularjs twitter-bootstrap

我点击Bootstrap Collapse选项的问题当我点击某个项目时我需要打开一些星形指令(uib-rating)我已经使用了UI-Bootstrap

HTML:

<p class="text-align" style="cursor:pointer"><a ng-click="fnDisplayQuestions(value.quesList.quesListName,$index)" data-toggle="collapse" data-target="{{#value.quesList.quesListName}}" >{{value.quesList.quesListName}}</a></p>
<uib-rating ng-model="rate" id="{{value.quesList.quesListName}}" class="collapse" max="max" read-only="isReadonly" on-hover="rating=value" ng-click="fnPutRating(rating)" on-leave="overStar = null" titles="['one','two','three']" aria-labelledby="default-rating"></uib-rating>

这些都在 ng-repeat 中,此处 value.quesList.quesListName 来自 ng-repeat 本身。

JS-CODE:

$scope.fnDisplayQuestions = function(qListName, index) { 

        $scope.indexQList = index;
        $scope.sQList = qListName;

        if (parseInt(window.localStorage.getItem('currentRound')) == 1) {
            getCandidateInterviewListService.fnGetQuestions(qListName).then(function(response) {
                $scope.aQuestions = response;
            });
        } else {
            getCandidateInterviewListService.fnGetQuesRoundBased(qListName).then(function(response) {
                $scope.aQuestions = response;
            });
        }

}

我不知道为什么这种崩溃不能正常工作。

2 个答案:

答案 0 :(得分:2)

您可以随时使用ng-if和某些条件,如下所示:

HTML:

<p class="text-align" style="cursor:pointer"><a ng-click="fnDisplayQuestions(value.quesList.quesListName,$index)"  >{{value.quesList.quesListName}}</a></p>
<uib-rating ng-model="rate" ng-if:"selectedQuestions" max="max" read-only="isReadonly" on-hover="rating=value" ng-click="fnPutRating(rating)" on-leave="overStar = null" titles="['one','two','three']" aria-labelledby="default-rating"></uib-rating>

JS:

$scope.fnDisplayQuestions = function(qListName, index) { 
$scope.selectedQuestions=true;          
    $scope.indexQList = index;
    $scope.sQList = qListName;
if (parseInt(window.localStorage.getItem('currentRound')) == 1) {
        getCandidateInterviewListService.fnGetQuestions(qListName).then(function(response) {
            $scope.aQuestions = response;
        });
    } else {
        getCandidateInterviewListService.fnGetQuesRoundBased(qListName).then(function(response) {
            $scope.aQuestions = response;
        });
    }

答案 1 :(得分:1)

我遇到了很多问题。我谷歌了解不同的解决方案,但没有帮助我,最后我遇到了这个解决方案。希望有人帮忙。

enter image description here

=&GT;这里我们需要使用服务器端控件绑定。 =&GT;我们可以使用c#codebeheind文件轻松完成此任务。

步骤1:在.aspx页面中为外部div写下父ID,并将其设为runat =“server”。我们将把我们的bootstrap tab div放在这个div中,以便我们可以轻松访问accordian类的子元素。

            <div class="panel-group accordion" runat="server" id="parenAccordian">                                   
                               <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <h4 class="panel-title">
                                            <a runat="server" href="Master.aspx?loadUC=One" data-target="#collapseOne" data-parent=".accordion"
                                                data-toggle="collapse" class="accordion-toggle tab_design" target="_self" aria-expanded="true" aria-controls="collapseOne">
                                                <span class="glyphicon glyphicon-plus" id="spanOne" runat="server"></span>
                                                <asp:Label ID="lblTabOne" runat="server" Text="TabOne"></asp:Label>
                                            </a>
                                        </h4>
                                    </div>
                                    <div class="panel-collapse collapse" runat="server" id="collapseOne">
                                        <div class="panel-body">
                                            <div runat="server" id="divOne">
                                            </div>
                                        </div>
                                    </div>
                                </div>


                               <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <h4 class="panel-title">
                                            <a runat="server" href="Master.aspx?loadUC=One" data-target="#collapseTwo" data-parent=".accordion"
                                                data-toggle="collapse" class="accordion-toggle tab_design" target="_self" aria-expanded="true" aria-controls="collapseOne">
                                                <span class="glyphicon glyphicon-plus" id="spanTwo" runat="server"></span>
                                                <asp:Label ID="lblTabTwo" runat="server" Text="TabTwo"></asp:Label>
                                            </a>
                                        </h4>
                                    </div>
                                    <div class="panel-collapse collapse" runat="server" id="collapseTwo">
                                        <div class="panel-body">
                                            <div runat="server" id="divTwo">
                                            </div>
                                        </div>
                                    </div>
                                </div>

        </div>

步骤2:重定向到母版页并将查询字符串作为参数传递以加载单击的用户控件。 whater是查询字符串参数,因为我们将采用该查询字符串参数将该usercontrol仅绑定到该div 例如:href =“Master.aspx?loadUC = One”

步骤3:在页面加载事件中编写代码

         string userControlID = ((System.Web.UI.Page)(sender)).ClientQueryString;
        var controlID = userControlID.Substring(userControlID.LastIndexOf('=') + 1);
        if (Request.QueryString["loadUC"] == controlID)
        {
            //get clicked control id
            HtmlGenericControl collapseDiv = (HtmlGenericControl)parenAccordian.FindControl("collapse" + controlID);
            collapseDiv.ID = "collapse" + controlID;
            collapseDiv.Attributes.Add("id", collapseDiv.ID);

            //load clicked user control and add bind to html div
            UserControl userControl = (UserControl)Page.LoadControl("~/UserControls/ModuleEngineering/SystemConfiguration/" + "UC" + controlID + "System.ascx");
            userControl.ID = "test";
            string userControlDivID = "div";
            string modifiedControlDivID = userControlDivID.Insert(3, controlID + "Data");

            HtmlGenericControl userControlDiv = (HtmlGenericControl)parenAccordian.FindControl(modifiedControlDivID);
            userControlDiv.ID = modifiedControlDivID;
            userControlDiv.Controls.Add(userControl);

            //add remove collapse plus minus class on click
            HtmlGenericControl spanDiv = (HtmlGenericControl)parenAccordian.FindControl("span" + controlID);
            spanDiv.ID = "span" + spanDiv;
            spanDiv.Attributes.Add("id", spanDiv.ID);

            string newTabValue = Convert.ToString(Session["NewCollapseTabValue"]);
            if (Session["NewCollapseValue"] == null)
            {
                Session["NewCollapseValue"] = "panel-collapse collapse";
            }
            if (Request.QueryString["loadUC"] == newTabValue)
            {
                if (Request.QueryString["loadUC"] == newTabValue)
                {
                    if (collapseDiv.Attributes["class"] != Convert.ToString(Session["NewCollapseValue"]))
                    {
                        collapseDiv.Attributes.Add("class", "panel-collapse collapse");
                        spanDiv.Attributes.Add("class", "glyphicon glyphicon-plus");
                    }
                    else
                    {
                        collapseDiv.Attributes.Add("class", "panel-collapse collapse in");
                        spanDiv.Attributes.Add("class", "glyphicon glyphicon-minus");
                    }
                }
                if (Request.QueryString["loadUC"] != newTabValue)
                {
                    if (collapseDiv.Attributes["class"] != Convert.ToString(Session["NewCollapseValue"]))
                    {
                        collapseDiv.Attributes.Add("class", "panel-collapse collapse in");
                        spanDiv.Attributes.Add("class", "glyphicon glyphicon-minus");
                    }
                    else
                    {
                        collapseDiv.Attributes.Add("class", "panel-collapse collapse");
                        spanDiv.Attributes.Add("class", "glyphicon glyphicon-plus");
                    }
                }
                Session["NewCollapseValue"] = collapseDiv.Attributes["class"];
            }
            if (Request.QueryString["loadUC"] != newTabValue)
            {
                if (collapseDiv.Attributes["class"] == Convert.ToString(Session["NewCollapseValue"]))
                {
                    if (collapseDiv.Attributes["class"] == Convert.ToString(Session["NewCollapseValue"]))
                    {
                        collapseDiv.Attributes.Add("class", "panel-collapse collapse in");
                        spanDiv.Attributes.Add("class", "glyphicon glyphicon-minus");
                    }
                    else
                    {
                        collapseDiv.Attributes.Add("class", "panel-collapse collapse");
                        spanDiv.Attributes.Add("class", "glyphicon glyphicon-plus");
                    }
                }
                else if (collapseDiv.Attributes["class"] != Convert.ToString(Session["NewCollapseValue"]))
                {
                    if (collapseDiv.Attributes["class"] != Convert.ToString(Session["NewCollapseValue"]))
                    {
                        collapseDiv.Attributes.Add("class", "panel-collapse collapse in");
                        spanDiv.Attributes.Add("class", "glyphicon glyphicon-minus");
                    }
                    else
                    {
                        collapseDiv.Attributes.Add("class", "panel-collapse collapse");
                        spanDiv.Attributes.Add("class", "glyphicon glyphicon-plus");
                    }
                }
                Session["NewCollapseValue"] = collapseDiv.Attributes["class"];
            }
            Session["NewCollapseTabValue"] = controlID;

步骤4:如果单击Bootstarp选项卡按钮或加号图标或Tab标题,它将从代码隐藏中添加'面板折叠崩溃'并删除面板折叠折叠类

步骤5:如果再次单击Bootstarp选项卡按钮或减去图标或Tab标题,它将从代码隐藏中添加“panel-collapse collapse”类并删除面板折叠折叠类。它将按预期工作。

步骤5:将你的所有页面绑定方法,dropdownlistbinding方法等方法放在Page_Init()的内容中