【问题标题】:Append multiple tags in text box in code behind using tagit jquery使用 tagit jquery 在代码后面的文本框中附加多个标签
【发布时间】:2018-05-15 07:59:20
【问题描述】:

我有一个 tagit 自动完成 jquery,它在搜索案例编号时运行良好。我正在尝试从后面的代码中附加一些已经插入文本框中的案例编号,并将其设置为案例编号的单独标签。它确实设置为标签,但我无法制作单个标签,因为它将所有案例编号组合到一个标签中。下面是我的代码。

class.cs

List<Models.Case> caseRefer = CaseCon.ViewById(SelectedCase.strId); // here I'm fetching case numbers from database with ',' for separation. 
            List<string> casenumbers = new List<string>();
            if (caseRefer[0].ReferCases!=null)
            {
                if (caseRefer[0].ReferCases != null)
                {
                    casenumbers = caseRefer[0].ReferCases.Split(',').ToList(); // here I'm spiting case numbers
                }

                foreach (var item in casenumbers)
                {
                    if (!item.Contains("<br />"))
                    {
                        txt_referCases.Text += item + Environment.NewLine; // here I'm trying to make all case numbers an individual tags but new line is not making any difference.
                    }
                }
            }

.aspx

 <asp:TextBox ID="txt_referCases" runat="server"></asp:TextBox>

<script>
 $(function () {


            var arr = [];

            var arrName = [];
 $('#<%=txt_referCases.ClientID %>').tagit({
     autocomplete: {
                    delay: 0,
                    minLength: 3,
                    source: function (request, response) {

                        $.ajax({
                            url: '<%=ResolveUrl("~/Case.aspx/ReferCases") %>',
                            data: "{ 'caseNum': '" + request.term + "'}",
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            success: function (data) {
                                arr = $.map(data.d, function (el) { return el });

                                response($.map(data.d, function (item, index) {

                                    return {
                                        label: item,
                                        val: index
                                    }
                                }))
                            },

                            error: function (response) {
                                alert(response.responseText);
                            },
                            failure: function (response) {
                                alert(response.responseText);
                            }
                        });
                    },

                } 
});

        });
</script>

【问题讨论】:

    标签: c# jquery tag-it


    【解决方案1】:

    终于解决了我自己的问题。只需将 Environment.NewLine 替换为 ',' 就可以了。所以这条线是

    txt_referCases.Text += item + ","

    这将分隔标签。

    【讨论】:

      猜你喜欢
      • 2015-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      相关资源
      最近更新 更多