Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

javascript - Function replicating items

The function is replicating each item that I place in. It runs through all of the panels, and places the additional items each time it runs. I have tried using the if statement that is placed but it is not working. I am placing the entire code block, but the issue starts at the let x = -1 variable. The full code block is strictly for reference. Please let me know if there is anything additional that I can provide. Additionally, .first() will not work for this instance.

function getRecordUI( alias, type, id, viewtype, version ) {

    // Get record model from Data Model Registry
    if ( type ) {
        getJSONUIModel( type,
            function ( data ) {
                displayRecordSections( alias, type, id, version, viewtype, data );
            },
            function (error) {
                console.log("Error getting UI model for type " + type);
                console.log(error);
                displayRecordSections( alias, type, id, version, viewtype, null );
            });
    } else {
        displayRecordSections( alias, type, id, version, viewtype, null );
    }
    let x = -1;
    lastName = "";

    $("#panels-region .panel-heading").each(function () {
        x++
            let curName = $(this).attr("name")
            if(!$('<a id="panels-sidebar-' + curName.replace(/ |//g, "_") + '" class="w3-bar-item" href="#panel-' + x + '-header" title="' + curName.replace(/ |//g, "_") + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' + curName + '</a>')) {
                $('<a id="panels-sidebar-' + curName.replace(/ |//g, "_") + '" class="w3-bar-item" href="#panel-' + x + '-header" title="' + curName.replace(/ |//g, "_") + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' + curName + '</a>').insertAfter("#panels-sidebar" + lastName.replace(/ |//g, "_"))
                break;
            }
                lastName = "-" + curName;
    });
    $("#graph-region .panel-heading h4").each(function () {
        x++
            let curName = $(this).text().replace("Collapse panelExpand panel", "")
                if(!$('<a id="tree_viewers-sidebar-' + curName.replace(/ |//g, "_") + '" class="w3-bar-item" href="#panel-' + x + '-header" title="' + curName.replace(/ |//g, "_") + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' + curName + '</a>')) {
                    $('<a id="tree_viewers-sidebar-' + curName.replace(/ |//g, "_") + '" class="w3-bar-item" href="#panel-' + x + '-header" title="' + curName.replace(/ |//g, "_") + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' + curName + '</a>').insertAfter("#tree_viewers-sidebar" + lastName.replace(/ |//g, "_"))
                    break;
                }
                    lastName = "-" + curName
    });
    $(".menu-links a").css("padding", "0px 8px")
    $(".panel-body").css("background-color", "white")
    $("#panels-region .panel-wrapper .panel-default").css("background-color", "white")
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...