我从MDL贡献者
Jonathan Garbee发现了
this MDL Github forum post的解决方案:
The component handler [ componentHandler.upgradeDom() ] will handle upgrading everything if you just call it with no parameters.
所以我的解决方案的伪代码是:
// Callback function of jquery-ui droppable element
drop: function(event, ui) {
// Add the element from it's template file
$.get("templates/" + elem + ".html", function(data) {
$("#canvas").append(data);
// Expand all new MDL elements
componentHandler.upgradeDom();
});
});
对于未来的材料设计精简版(MDL)框架的读者和用户,您还可以单独刷新动态添加的元素(而不是整理整个DOM).
例如,componentHandler.upgradeDom(“mdl-menu”)将仅升级mdl菜单元素.