后台菜单是ajax获取后解析json生成的html片段然后html()添加进去的,jq似乎无法选择这些新增的节点,请问该如何解决?
function _tree(rows)
{
var str = '';
$.each(rows, function(i, e) {
var li_class = typeof(e.children) == 'undefined' ? '' : 'treeview';
var allow_a = typeof(e.children) == 'undefined' ? 'data-menuid='+e.id : '';
var menu_icon = e.menu_icon == '' ? 'link' : e.menu_icon;
var menu_link = typeof(e.children) == 'undefined' ? e.menu_link : '#';
var container = typeof(e.children) == 'undefined'
? ''
: ''+
''+
'';
str += '
'+e.menu_name+''+container+'';if (typeof(e.children) != 'undefined') {
str += '
str += _tree(e.children);
str += '
';}
str += '
';});
return str;
}
$(function() {
_get({type: 'json'}, Japi.menuGet, function(respond) {
if (respond.code.errcode == Japi.SUCCESS_STATUS) {
$('#admin-menu').html(_tree(respond.data));
}
});
当我选择节点的时候
var n = $('#admin-menu [data-menuid='+nowId+']');
console.log(n);
似乎找不到这个节点,请问问题处在什么地方