简体   繁体   English

如何在javascript中应用已填充行的条件?

[英]How to apply the condition in javascript that row has been filled?

Actually I am retrieving some data from database through ajax and on retrieval of data i made some dynamic element in html using javascript. 实际上,我正在通过ajax从数据库中检索一些数据,并在检索数据时使用javascript在html中创建了一些动态元素。 I made dynamic row in a container and in that row i making a dynamic div whose class is "col-md-4" it means there can be atleast 3 divs in a dynamic .... Now no. 我在容器中创建了动态行,并在该行中创建了一个动态div,其类为“ col-md-4”,这意味着动态中至少可以有3个div。 of divs whose class is col-md-4 depends upon the rows retrieved from database it means everytime when data is retrieved there will be a new row in which a new div will form with only div col-md-4. 类为col-md-4的div的数量取决于从数据库中检索到的行,这意味着每次检索数据时,都会有一个新行,其中仅div col-md-4会形成一个新的div。 Now i want there should be 3 divs of class-md-4 should be created then new should be created 现在我希望应该创建3个div-class-4 mds然后创建new

    $.ajax({
                url: '../php/admin/upcoming_match.php',
                type: 'post',
                data: {},
                success: function(response) {
                    var n=1;
                    var data = JSON.parse(response);
                    if(data!=''){
                        $.each(data, function(i, item) {
                            var parent= document.getElementsByClassName('carousel')[0];
                            var row1= document.createElement("div");
                            row1.setAttribute("class","row");
                            row1.setAttribute("id","row"+n);
                            parent.appendChild(row1);
                            var child=document.getElementbyId('row'+n);
                            var crow1= document.createElement("div");
                            crow1.setAttribute("class","col-md-4");
                            crow1.setAttribute("id",data[i].id);
                            row1.appendChild(crow1);
                          n++;
                          return n;
                        });

                    }
                }
            });

In this code the new dynamic will have only one child div ... i want should have atleast 3 child divs. 在这段代码中,新的动态将只有一个子div ...我希望至少有3个子div。 For eg, if we retrieved 4 rows from database then there should a new dynamic row which should have 3 child divs that contain the data of 3 rows then there should be a new row which should 4th child div row but in my present if i retrieve 4 rows then 4 news row class are formed which contain a child div that contain the data of each row retrieved from database 例如,如果我们从数据库中检索了4行,那么应该有一个新的动态行,该行应该有3个子div,其中包含3行的数据,那么应该有一个新行,它应该有第4个子div行,但是如果我检索形成4行然后4个新闻行类,其中包含一个子div,该子div包含从数据库中检索到的每一行的数据

What about something like this ? 那这样的事情呢?
It would be easier to have demo data. 拥有演示数据会更容易。 You can upvote or accept if you like that. 如果您愿意,您可以投票或接受。

 var ajax = prompt('Confirm demo or paste AJAX data', '[ {"id":1}, {"id":2}, {"id":3}, {"id":4}, {"id":5}, {"id":6}, {"id":7}, {"id":8}, {"id":9}, {"id":"A"} ]'); display(ajax); function display(response) { var n=1; var data = JSON.parse(response); if(data.length) { for(var i=0;i<data.length;i++) { var parent= document.getElementsByClassName('carousel')[0]; var row1= document.createElement("div"); row1.setAttribute("class", "row"); row1.setAttribute("id", "row"+n); parent.appendChild(row1); var crow1; for(var j=0;j<3 && i+j < data.length;j++) { crow1 = document.createElement("div"); crow1.setAttribute("class", "col-md-4"); crow1.setAttribute("id", data[i+j].id); crow1.innerText = "data" + (i+j) + " id" + data[i+j].id; row1.appendChild(crow1); } i += 3-1; n++; } } } 
 DIV.col-md-4 { display: inline; background-color: #FF0080; margin: 5px; } .row { display: block; background-color: #80E080; padding: 3px; } 
 <div class="carousel"> </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何显示尚未填写的字段 - How to display which field has not been filled in 如何查看表天气是否已满? - How to check table weather is has been filled or not? 禁用表单字段,直到前一个字段已被JavaScript填充 - Disable form fields until a previous field has been filled with JavaScript 如何在 Google Appscript 中编写 IF 条件以仅在单元格自首次填充后超过 2 天处于活动状态时触发事件 - How to write an IF condition in Google Appscript to trigger an event only if cell has been active > 2 days from the time it was first filled up 如何仅在更新行后将公式应用于 Google 表格行? - How can I apply a formula to a Google Sheet row only after a row has been updated? Angular如何应用条件路由,条件是确保上一页已经被访问过? - How to apply conditional routing in Angular where the condition is to make sure that the previous page has been visited? 如何禁用div,直到填写上一个div - How to disable div(s) until previous div has been filled in 如何通知 AngularJS 表单已由 jQuery 从外部填充? - How to notify AngularJS that a form has been filled externally by jQuery? 如何在 JavaScript 过滤器中应用条件 - How to apply a condition in JavaScript filter 插入到已用空 Arrays 填充的二维数组的行中时,元素被添加到每一行 - elements are being added to every row when inserting into a row for a 2D array that has been filled with empty Arrays
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM