Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
嵌套。每个jquery都附加到类中_Jquery_Ajax - Fatal编程技术网

嵌套。每个jquery都附加到类中

嵌套。每个jquery都附加到类中,jquery,ajax,Jquery,Ajax,我有一个嵌套的。每个 $.each(result.postsViewModel.Posts, function(index, item) { $('#postList').append('<div class="col-lg-4 postItem"><div class="ibox"><div class="ibox-content contact-box">' + (item.IsPublic == true ? '<span class="l

我有一个嵌套的。每个

$.each(result.postsViewModel.Posts, function(index, item) {
    $('#postList').append('<div class="col-lg-4 postItem"><div class="ibox"><div class="ibox-content contact-box">' + (item.IsPublic == true ? '<span class="label label-primary pull-right">Public</span>' : '<span class="label label-warning pull-right">Private</span>') + '<a href="@Url.Action("Article", "AppViews")" title="' + item.Title + '" class="btn-link"><h2><span class="postId">' + item.PostId + '</span>. ' + item.Title + '</h2></a><div class="small m-b-xs"><strong>' + item.Category.Name + '</strong> <div class="text-muted"><i class="fa fa-clock-o"></i> ' + new Date(parseInt(item.PostedOn.substr(6))) + '</div></div><p>' + $.trim(item.Description.replace(regex, "")).substring(0, 200).trim(this) + '...' + '</p><div class="row"><div class="col-md-6 tags"><h5>Tags:</h5></div><div class="col-md-6"><div class="small text-right"><h5>Stats:</h5><div><i class="fa fa-comments-o"> </i> 56 comments</div><i class="fa fa-eye"> </i> 144 views</div></div></div><div class="contact-box-custom-footer"><div class="m-t-xs btn-group"><a class="btn btn-xs btn-white deletePostBtn"><i class="fa fa-trash"></i> Remove </a></div></div></div></div></div>');

    $.each(item.Tags, function(index, tag) {
        $('.tags').append('<button class="btn btn-white btn-xs" type="button">' + tag.Name + '</button> ');
    });
});
$。每个(result.postsViewModel.Posts,函数(索引,项){
$(“#postList”).append(“”+(item.IsPublic==true?'Public':“Private”)+“”+item.Category.Name+“”+新日期(parseInt(item.PostedOn.substr(6))+“”+$.trim(item.Description.replace(regex)”))。子字符串(0,200)。trim(此)+'..'+'

标记:统计信息:56条注释144个视图'+item.Category.Name+''+新日期(parseInt(item.PostedOn.substr(6))+''+$.trim(item.Description.replace(regex)”)。子字符串(0200.trim(this)+'.+''+'

标记:统计信息:56条注释144个视图删除'; $.each(item.Tags,函数(index,tag){ post.find('.tags').append(''+tag.Name+''); }); $('#postList')。追加(post); });
首先,要回答您的问题,您可以创建一个Jquery元素并在将其附加到DOM之前向其添加按钮:

$.each(result.postsViewModel.Posts, function (index, item) {
    var $el = $('<div>Your content</div>');

    $.each(item.Tags, function (index, tag) {
         $el.find('.tags').append('<button class="btn btn-white btn-xs" type="button">' + tag.Name + '</button> ');
    });

    $('#postList').append($el);
});
$。每个(result.postsViewModel.Posts,函数(索引,项){
var$el=$(“您的内容”);
$.each(item.Tags,函数(index,tag){
$el.find('.tags').append(''+tag.Name+'');
});
$('#postList')。追加($el);
});

请注意,创建所有节点并将它们附加在一起更有效,而不是每次循环迭代一次。

首先,要回答您的问题,您可以创建一个Jquery元素并在将其附加到DOM之前向其添加按钮:

$.each(result.postsViewModel.Posts, function (index, item) {
    var $el = $('<div>Your content</div>');

    $.each(item.Tags, function (index, tag) {
         $el.find('.tags').append('<button class="btn btn-white btn-xs" type="button">' + tag.Name + '</button> ');
    });

    $('#postList').append($el);
});
$。每个(result.postsViewModel.Posts,函数(索引,项){
var$el=$(“您的内容”);
$.each(item.Tags,函数(index,tag){
$el.find('.tags').append(''+tag.Name+'');
});
$('#postList')。追加($el);
});

只需提到,创建所有节点并将它们附加在一起更为有效,而不是每次循环迭代都附加一次。

是否将所有节点附加到1个div?是否可以只给这个ID?另外,请您在问题中加入更多HTML,包括第一个
#postList
。我创建的每个都包含每个帖子的所有标记。在第二个.each中,我将所有按钮附加到我刚刚创建的标记div中,因此页面上有多个按钮,对于每个项.tags,它将附加到每个标记div,但我只希望它附加到我刚刚创建的div中,而不是全部。是否将所有按钮附加到1 div中?是否可以只给这个ID?另外,请您在问题中加入更多HTML,包括第一个
#postList
。我创建的每个都包含每个帖子的所有标记。在第二个。每个,我都将所有按钮附加到我刚刚创建的标记div中,因此页面上有几个按钮,对于每个项目。标记,它附加到每个标记div中,但我只希望它附加到我刚刚创建的div中,而不是全部。这并没有解决我的问题,对于我的每个帖子,我都附加一个类“tags”,然后对于我的每个帖子标记,我将按钮附加到“tags”类,因此它将附加到tags类的每个实例,您的解决方案只允许我在切换操作之前创建一个元素,而忽略了“tags”类元素。修好了。现在好了吗?事实上,您的第一个答案是有效的,它显示了$el元素的[object object],将其更改为$el.Html();它成功了,第二次编辑非常完美。谢谢你的回答。我在寻找它,但这并不能解决我的问题,对于我的每一篇文章,我都会附加一个类“tags”,然后对于我的每一篇文章标记,我会将按钮附加到“tags”类,所以它会附加到tags类的每一个实例,你的解决方案只允许我在handops之前创建一个元素,错过了“tags”类元素。修好了。现在好了吗?事实上,您的第一个答案是有效的,它显示了$el元素的[object object],将其更改为$el.Html();它成功了,第二次编辑非常完美。谢谢你的回答。我在找它
$.each(result.postsViewModel.Posts, function (index, item) {
    var $el = $('<div>Your content</div>');

    $.each(item.Tags, function (index, tag) {
         $el.find('.tags').append('<button class="btn btn-white btn-xs" type="button">' + tag.Name + '</button> ');
    });

    $('#postList').append($el);
});