Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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
如何在JavaScript上为对象列表创建循环_Javascript_Jquery_Ajax_List - Fatal编程技术网

如何在JavaScript上为对象列表创建循环

如何在JavaScript上为对象列表创建循环,javascript,jquery,ajax,list,Javascript,Jquery,Ajax,List,我得到的ajax结果是一个对象列表,我需要为列表中的每个对象显示一些查找文本的结果,每个对象与其他textarea类似,我找到了如何为一个textarea生成文本的方法: success: function(data) { setTimeout("$('.loader').hide()", 2000); setTimeout("$('#lblack').hide()", 2000); console.log(data); var cheked_text;

我得到的ajax结果是一个对象列表,我需要为列表中的每个对象显示一些查找文本的结果,每个对象与其他textarea类似,我找到了如何为一个textarea生成文本的方法:

 success: function(data) {
    setTimeout("$('.loader').hide()", 2000);
    setTimeout("$('#lblack').hide()", 2000);
    console.log(data);

    var cheked_text;
    $.each(data[0].WordInfos, function(index, value) {
        if (value.q > 0) {
            var wr = value.w.fontcolor("red");
            cheked_text = text.replace(new RegExp(value.w, 'g'), '<b>' + wr + '</b>');
            text = cheked_text;
        }
    });
    var sub_ul = $('<ul/>');
    $.each(data[0].WordInfos, function(index, value) {
        var sub_li = $('<li/>');
        $(sub_li).html(value.w + "-" + value.q);
        $(sub_li).appendTo(sub_ul);
    });
    var exresult = document.getElementById("searchresult");
    var appendContent = $("<section id='searchresult'><h4>Result:</h4><div class='words'><b>Words:</b></div><div class='text'><b>Text:</b><br>" + text + "</div></section>");
    if (exresult == null) {
        $(appendContent).find(".words").append(sub_ul);
        $(".Results").append(appendContent);
    } else {
        $("#searchresult").html("<h4>Result:</h4><div class='words'>Words:</div><div class='text'>Text:<br>" + text + "</div>")
        $("#searchresult").find(".words").append(sub_ul);
    }
},
找到了解决方案

                       setTimeout("$('.loader').hide()", 2000);
                    setTimeout("$('#lblack').hide()", 2000);
                    console.log(data);
                    $.each(data, function (index, value) {
                        var cheked_text;
                        var Edit_text = value.text;
                        $.each(value.WordInfos, function (index, value) {
                            if (value.q > 0) {
                                var wr = value.w.fontcolor("red");
                                cheked_text = Edit_text.replace(new RegExp(value.w, 'g'), '<b>' + wr + '</b>');
                                Edit_text = cheked_text;
                            }
                        });
                        var sub_ul = $('<ul/>');
                        $.each(value.WordInfos, function (index, value) {
                            var sub_li = $('<li/>');
                            $(sub_li).html(value.w + "-" + value.q);
                            $(sub_li).appendTo(sub_ul);
                        });
                        var exresult = document.getElementById("searchresult");
                        var appendContent = $("<section id='searchresult'><h4>Result:</h4><div class='words'><b>Words:</b></div><div class='text'><b>Text:</b><br>" + Edit_text + "</div></section>");

                            $(appendContent).find(".words").append(sub_ul);
                            $(".Results").append(appendContent);

                    });
setTimeout(“$('.loader').hide()”,2000);
setTimeout(“$('#lblack').hide()”,2000);
控制台日志(数据);
$.each(数据、函数(索引、值){
var cheked_文本;
var Edit_text=value.text;
$.each(value.WordInfos,函数(索引,值){
如果(q值>0){
var wr=w.fontcolor(“红色”)的值;
cheked_text=Edit_text.replace(新的RegExp(value.w,'g'),''+wr+'';
编辑文本=勾选文本;
}
});
var sub_ul=$(“
    ”); $.each(value.WordInfos,函数(索引,值){ var sub_li=$(“
  • ”); $(sub_li).html(value.w+“-”+value.q); $(附属法例)。附件(附属法例); }); var exresult=document.getElementById(“searchresult”); var appendContent=$(“结果:单词:文本:
    ”+编辑文本+”); $(appendContent.find(“.words”).append(sub_ul); $(“.Results”).append(appendContent); });
找到了解决方案

                       setTimeout("$('.loader').hide()", 2000);
                    setTimeout("$('#lblack').hide()", 2000);
                    console.log(data);
                    $.each(data, function (index, value) {
                        var cheked_text;
                        var Edit_text = value.text;
                        $.each(value.WordInfos, function (index, value) {
                            if (value.q > 0) {
                                var wr = value.w.fontcolor("red");
                                cheked_text = Edit_text.replace(new RegExp(value.w, 'g'), '<b>' + wr + '</b>');
                                Edit_text = cheked_text;
                            }
                        });
                        var sub_ul = $('<ul/>');
                        $.each(value.WordInfos, function (index, value) {
                            var sub_li = $('<li/>');
                            $(sub_li).html(value.w + "-" + value.q);
                            $(sub_li).appendTo(sub_ul);
                        });
                        var exresult = document.getElementById("searchresult");
                        var appendContent = $("<section id='searchresult'><h4>Result:</h4><div class='words'><b>Words:</b></div><div class='text'><b>Text:</b><br>" + Edit_text + "</div></section>");

                            $(appendContent).find(".words").append(sub_ul);
                            $(".Results").append(appendContent);

                    });
setTimeout(“$('.loader').hide()”,2000);
setTimeout(“$('#lblack').hide()”,2000);
控制台日志(数据);
$.each(数据、函数(索引、值){
var cheked_文本;
var Edit_text=value.text;
$.each(value.WordInfos,函数(索引,值){
如果(q值>0){
var wr=w.fontcolor(“红色”)的值;
cheked_text=Edit_text.replace(新的RegExp(value.w,'g'),''+wr+'';
编辑文本=勾选文本;
}
});
var sub_ul=$(“
    ”); $.each(value.WordInfos,函数(索引,值){ var sub_li=$(“
  • ”); $(sub_li).html(value.w+“-”+value.q); $(附属法例)。附件(附属法例); }); var exresult=document.getElementById(“searchresult”); var appendContent=$(“结果:单词:文本:
    ”+编辑文本+”); $(appendContent.find(“.words”).append(sub_ul); $(“.Results”).append(appendContent); });
提供
数据
输出用于编辑,添加了数据输出示例。提供
数据
输出用于编辑,添加了数据输出示例。
                       setTimeout("$('.loader').hide()", 2000);
                    setTimeout("$('#lblack').hide()", 2000);
                    console.log(data);
                    $.each(data, function (index, value) {
                        var cheked_text;
                        var Edit_text = value.text;
                        $.each(value.WordInfos, function (index, value) {
                            if (value.q > 0) {
                                var wr = value.w.fontcolor("red");
                                cheked_text = Edit_text.replace(new RegExp(value.w, 'g'), '<b>' + wr + '</b>');
                                Edit_text = cheked_text;
                            }
                        });
                        var sub_ul = $('<ul/>');
                        $.each(value.WordInfos, function (index, value) {
                            var sub_li = $('<li/>');
                            $(sub_li).html(value.w + "-" + value.q);
                            $(sub_li).appendTo(sub_ul);
                        });
                        var exresult = document.getElementById("searchresult");
                        var appendContent = $("<section id='searchresult'><h4>Result:</h4><div class='words'><b>Words:</b></div><div class='text'><b>Text:</b><br>" + Edit_text + "</div></section>");

                            $(appendContent).find(".words").append(sub_ul);
                            $(".Results").append(appendContent);

                    });