简体   繁体   English

为每个结果实现CSS初始化选项卡

[英]Materialize css initializing tabs for each result

I am doing a school project that is a Movie lookup app connected to guidebox API. 我正在做一个学校项目,该项目是连接到guidebox API的电影查找应用程序。 I am using Materialize CSS and trying to organize the information into their tabs system. 我正在使用Materialize CSS,并尝试将信息组织到其选项卡系统中。 They are added dynamically so the documentation says to initialize in javascript. 它们是动态添加的,因此文档说要使用javascript进行初始化。 It says to use: 它说使用:

      $(document).ready(function(){
         $('ul.tabs').tabs();
      });

However that doesn't work for me I guess since the tabs are not present at Doc Ready thaey are not pushed into the DOM until a submit request. 但是,我认为这对我不起作用,因为Doc Ready文档中不存在这些选项卡,直到提交请求之前,这些标签才被推入DOM。 I put just the 我把

      $('ul.tabs').tabs(); 

into a few places in my code and the best result was it working on the first movie returned on each search but for each subsequent return item the tabs break. 放到我的代码中的几个位置,最好的结果是它可以处理每次搜索返回的第一部电影,但是对于每个后续返回项,制表符都会中断。

I could use some guidance on whether I can plug that in somewhere to make my existing code work. 对于是否可以将其插入某个地方以使现有代码正常工作,我可以使用一些指导。

https://github.com/jasonboru/group_project1_guidebox.git https://github.com/jasonboru/group_project1_guidebox.git

There are some missing ending tags in your dynamically created dom elements. 动态创建的dom元素中缺少一些结束标签。

Apart this, in this file assets/js/logic.js the following there are the following two lines: 除此之外,在此文件assets / js / logic.js中,以下两行内容:

$('.guidebox-search-results').append(movieResult);
$('ul.tabs').tabs();  

That menas, whenever you add new tabs element you initialize them. 该菜单,无论何时添加新的tab元素,都将对其进行初始化。 The mistake I see is: in this way you initialize every tabs not only the new one. 我看到的错误是:这样,您不仅初始化了每个选项卡,还初始化了每个选项卡。 And, because you have already initilized the old one I can suggest you to rewrite the previous two lines in this format: 并且,由于您已经初始化了旧的代码,因此我建议您以这种格式重写前两行:

$('.guidebox-search-results').append(movieResult);
$('.guidebox-search-results').find('ul.tabs').tabs();  

You can bind on every event, when node inserted in dom and after that, do with it what you want. 您可以对每个事件进行绑定,将节点插入dom后,然后再按所需操作即可。

$(document).bind('DOMNodeInserted', function(e) {
    var element = e.target;
});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM