[英]riot.js nested tags - how can I select an inner html element with jquery?
I have a riot tag which contains a nested tag... example:我有一个包含嵌套标签的 riot 标签......例如:
<parent>
<!-- dome html here...-->
<child></child> <!-- visually - the child is mounted correctly !-->
<script>
this.on('mount', function(){
$('select').material_select();
});
</script>
</parent>
<child>
<select>
<option values="1">1</option>
<option values="2">2</option>
<option values="3">3</option>
</select>
<script>
this.on('mount', function(){
$('select').material_select();
});
</script>
</child>
Now, I want to use the Materialize library and jquery to make the list materialize-designed such as in http://materializecss.com/forms.html It usually works fine when the 'select' tag is in a parent tag!现在,我想使用 Materialize 库和 jquery 来使列表具体化设计,例如在http://materializecss.com/forms.html当“select”标签位于父标签中时,它通常可以正常工作!
However, I cant find where to initialize the $('select').material_select();
但是,我找不到在哪里初始化
$('select').material_select();
command in the child, and thus, the select tag in the child tag is not visible!.子标签中的命令,因此,子标签中的 select 标签不可见!。
I have tried to initialize it inside the on('mount') area both of the parent and the child tags - but it seems as always the $('select') selector return an empty array - any ideas?我试图在父标签和子标签的 on('mount') 区域内初始化它 - 但似乎 $('select') 选择器总是返回一个空数组 - 有什么想法吗?
You can try to force the children to update and then call the on('updated') event on the child, because it´s seems that the DOM is not ready onMount.您可以尝试强制孩子更新,然后在孩子上调用 on('updated') 事件,因为 DOM 似乎还没有准备好 onMount。 Check this example.
检查这个例子。
<parent>
<!-- dome html here...-->
<child></child> <!-- visually - the child is mounted correctly !-->
<script>
this.on('mount', function(){
this.update();
});
</script>
</parent>
<child>
<div>
<select>
<option values="1">1</option>
<option values="2">2</option>
<option values="3">3</option>
</select>
</div>
<script>
this.on('updated', function(){
$('select').material_select();
});
</script>
</child>
online version https://jsfiddle.net/vitomd/Lm4dy21d/5在线版https://jsfiddle.net/vitomd/Lm4dy21d/5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.