각 목록 항목에 데이터 태그로 값이 추가 된 정렬되지 않은 항목 목록이 있습니다. 사용자가 목록에서 항목을 선택하면 li가 사라지고 데이터 태그가 별도의 셀로 표에 인쇄되고 모든 데이터가 배열로 저장됩니다. 각 항목을 다른 목록에 추가 할 수 있었지만 표 행으로 추가하기가 어려웠습니다.데이터 태그가있는 jQuery 배열과 테이블에 인쇄
나는 그것이 'append'의 사용이라고 생각하지만, li은 테이블 내에서 추가되고 배열에 추가하는 현재 순서에 따라 데이터가 합성됩니다.
주문을 클릭하고 배열에 추가 한 다음 테이블에 인쇄해야한다고 생각합니다.
Here is a link to my most recent.
사전에 도움을 주셔서 감사합니다. 귀하의 질문에서var myArraySelected = [] ;
$(function() {
var myFunc = function() {
myArraySelected = [] ;
var userList = $('#selected');
userList.children('li').each(function() {
var userID = $(this).attr('data-user');
var userService = $(this).attr('data-role');
var userCategory = $(this).attr('data-category');
var userName = $(this).attr('data-name');
myArraySelected.push({
'id':userID,
'name':userName,
'role':userService,
'category' :userCategory
});
});
};
$('#userList li').click(function() {
$(this).fadeOut('slow', function() { // code to run after the fadeOut
$(this).append('<tr><td><p>'+ $(this).attr('data-name') + '<br>' + $(this).attr('data-user') + '<br>' + $(this).attr('data-role') + '<br>' + $(this).attr('data-category') + '</p></td></tr>')
$(this).appendTo('#selected').fadeIn('slow');
myFunc();
});
});
myFunc();
});
미안하지만 귀하의 궁금한 점은 무엇입니까? – JMax