JQuery basic selector usage and non unique element ID

前端 未结 4 768
别那么骄傲
别那么骄傲 2021-01-22 10:38

I\'am maintaining a GUI built using JQuery. In one part of the GUI, multiple tabs can be opened to edit data.

When a new tab is opened, it is created by cloning the firs

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-22 11:25

    I have a AngularJS app where I ran into the same problem when ng-repeating elements. Heres how I solved it.

    Your tabs, the parent element, have unique ID's right? So just go down the children of that tab. Snipit from my div-windows to get children for resizable parent and alsoResize (or manualy resize as in my case) the children. Hint: I just left the IDs out of the children. $scope.panes[] is my window array, I just grab the ID and each out the children:

    var objParent = $('#' + $scope.panes[index].windID); //entire div window
    var objChild = [];
    //objChild[0] = title bar
    //objChild[1] = contentpane
    objParent.children().each(function(i){
        objChild[i] = $(this);
    });
    

    Another solution would be to built the whole tab as a string and innerHTML it to the page. This way you can do someting like this with the ids: (again my div-window example)

    child1ID = "id='"+windID+titlebar+"'";
    child2ID = "id='"+windID+contentpane+"'";
    

提交回复
热议问题