代码之家  ›  专栏  ›  技术社区  ›  Katerine459

正在将带有属性的XML文件加载到JQuery数组中…数组为空

  •  0
  • Katerine459  · 技术社区  · 6 年前

    我希望这是一个相当简单的解决方案,但我花了一整天的时间才走到这一步,我很难找出问题所在。

    我有一个叫做作业标签列表.xml:

    <Tags><Tag Tag="consolidated"/><Tag Tag="test"/></Tags>
    

        <script src="../Scripts/jquery-ui-1.12.1.min.js"></script>
        <script src="../Scripts/tag-it.min.js"></script>
    
        <script type="text/javascript">
            $(document).ready(function () {
                var isrecurring = $("#<%=IsRecurringJob.ClientID %>").prop('checked');
    //            console.log(isrecurring);
                if (isrecurring) {
                    $(".showwhenrecurring").show();
                } else {
                    $(".showwhenrecurring").hide();
                }
    
                var jobid = $("#<%=JobID.ClientID %>");
                if (jobid.val() != null && jobid.val() != '') {
                } else {
                    $(".hidewhennew").hide();
                }
    
    
            });
    
            //tags handling starts here
            function split(val) {
                return val.split(/,\s*/);
            }
            function extractLast(term) {
                return split(term).pop();
            }
    
            $(function () {
                var tagslist = new Array();
                $.ajax({
                    type: "GET",
                    url: "../XML/JobTagsList.xml",
                    dataType: "xml",
                    success: function (xml) {
    
                        //but if it's multible items then loop
                        $(xml).find('Tag').each(function () {
                            tagslist.push($(this).attr('Tag'));
                        });
                    }
                });
    
                $("#<% =txtTags.ClientID %>")
                    .on("keydown", function (event) {
                        if (event.keyCode === $.ui.keyCode.TAB &&
                            $(this).autocomplete("instance").menu.active) {
                            event.preventDefault();
                        }
                    });
    
                $("#<% =txtTags.ClientID %>").tagit({
                    availableTags: tagslist,
                    // This will make Tag-it submit a single form value, as a comma-delimited field.
                    singleField: true,
                    singleFieldNode: $("#<% =txtTags.ClientID %>")
                });
    
            });
    
            function fixform() {
                if (opener.document.getElementById("PageForm").target != "_blank") return;
                opener.document.getElementById("PageForm").target = "";
                opener.document.getElementById("PageForm").action = opener.location.href;
            }
        </script>
    

    代码编译时没有错误,但是根据Chrome调试器的说法,tagslist数组是空的,这时它应该有两个项目(['test','consolidated'])。请帮忙。:)

    0 回复  |  直到 6 年前