在Java的Polymer Element模板中添加或附加HTML

编程入门 行业动态 更新时间:2024-10-06 22:24:00
本文介绍了在Java的Polymer Element模板中添加或附加HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为了使旋转木马功能在Polymer元素内部工作,我正在以编程方式在我的元素脚本内创建Slick旋转木马所需的标记.假定此代码段已将this.videos作为包含youtube视频信息(特别是id和name属性)的对象数组加载:

In an attempt to get carousel functionality working inside of a Polymer element, I am programmatically creating the markup needed for the Slick carousel inside of my element's script. Assume in this code snippet that this.videos has already been loaded as an array of objects that contain youtube video information, specifically an id and name property:

// Create Carousel Container var carousel = $('<div id="carousel"></div>'); // Add Slides this.videos.forEach(function(element, index, array){ // Create a template for each slide var slideTemplate = $('<div><iframe width="420" height="315" src="//www.youtube/embed/' + element.id + '" frameborder="0" allowfullscreen></iframe></div>'); // Append Each Slide to the Carousel slideTemplate.appendTo(carousel); // jQuery Method $('#carousel').appendChild("<div></div>"); });

上面的"append *"方法都不起作用,并且结果DOM不包含div#carousel元素.将HTML添加到Polymer元素模板的正确方法是什么?

Neither of the "append*" methods above are working, and the resultant DOM contains no div#carousel element. What is the proper way to add HTML to a Polymer element's template?

这是先前的SO问题,我问这解释了为什么我必须尝试这种从javascript元素内部注入标记的方法.这与标记中挥之不去的模板标签有关>在UPDATE 2下查找完整的摘要.

Here is a previous SO question I asked that explains why I have to attempt this method of injecting markup inside the element from javascript. It has to do with that lingering template tag in the markup > look under UPDATE 2 for the full run-down.

推荐答案

没有理由编写代码:)做到这一点的最佳方法是使用Polymer的数据绑定功能,而不是提前设置DOM模板.通常,您永远不需要像这样触摸DOM.这是基本概念:

There's no reason to write code :) The best way to do this is use Polymer's data-binding features rather and setup the DOM template ahead of time. In general, you should never need to touch the DOM like this. Here's the basic idea:

<div id="carousel"> <template repeat="{{v in videos}}"> <div><iframe src="//www.youtube/embed/{{v.id}}"></iframe></div> </template> </div>

填充this.videos后,模板引擎将自动为您标记标记.

When this.videos is populated, the template engine will automatically stamp the markup for you.

更多推荐

在Java的Polymer Element模板中添加或附加HTML

本文发布于:2023-08-03 06:34:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1284896.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   Polymer   Java   HTML   Element

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!