можете ли вы рассказать мне, как добавить строку в панель, которая является разборной строкой (может быть расширена), я могу добавить, но она не расширяется.
Я делаю эту ошибку, выполняя этот шаг. Первый щелчок на значке << откройте левую панель. Затем я нажимаю кнопку "Добавить", она генерирует строку, а также генерирует подменю firstLevel. Затем нажмите кнопку +, чтобы она расширялась. Но когда вы снова нажимаете кнопку "Добавить", она генерирует еще одну строку и подменю но он не расширяется при нажатии на кнопку +?
http://jsfiddle.net/eHded/1549/
function addInmenu(id){
alert(id)
var menuid="menu_"+id;
// var data = $('#menuId li').html();
$('#menuId li').append('<ul><li id=' + menuid + '><a>'+menuid+'</a></li></ul>');
$('.tree li').each(function () {
if ($(this).children('ul').length > 0) {
$(this).addClass('parent');
}
});
$('.tree li.parent > a').on('click',function () {
//alert('--')
$(this).parent().toggleClass('active');
$(this).parent().children('ul').slideToggle('fast');
});
}
Вот ваш код, работающий в jsfiddle
function addInmenu(id){
var menuid="menu_"+id;
// var data = $('#menuId li').html();
$('#menuId li:first ').append('<ul><li id=' + menuid + '><a>'+menuid+'</a></li> </ul>');
$('.tree li').each(function () {
if ($(this).children('ul').length > 0) {
$(this).addClass('parent');
}
});
$('.tree li.parent > a').unbind("click");
$('.tree li.parent > a').on('click',function () {
//alert('--')
$(this).parent().toggleClass('active');
$(this).parent().children('ul').slideToggle('fast');
});
}
$('#add').click(function () {
var listItems = $("#ultest").children();
var id;
if (typeof ($("#ultest li:last").attr('id')) == 'undefined') {
//alert('undefint');
id = "tc_1"
} else {
id = $("#ultest li:last").attr('id');
var index = id.indexOf("_");
var count = id.substring(index + 1, id.length)
count = parseInt(count);
id = id.substring(0, index) + "_" + parseInt(count + 1);
// alert(id)
}
if ($('.tree li.parent').hasClass('active')){
$('.tree li.parent').toggleClass('active');
$('.tree li.parent').children('ul').slideToggle('fast');
}
$('#ultest').append('<li id=' + id + '><a href="#" class="foo">' + id + '</a></li>');
//$('#ultest').listview('refresh');
addInmenu(id);
});
ОБНОВЛЕНО:
здесь обновляется скрипка для справки jsfiddle здесь