The initialization method of some components in MDUI is to execute the initialization function after the DOM is loaded, which causes the component to be unable to be initialized automatically when the component is dynamically generated. MDUI provides the mdui.mutation()
method to solve this problem.
After calling this method, all uninitialized components in the page will be initialized.
var html =
'<select class="mdui-select" mdui-select>' +
' <option value="1">State 1</option>' +
' <option value="2">State 2</option>' +
' <option value="3">State 3</option>' +
'</select>';
// A Select component is dynamically added, but it cannot be initialized automatically when it is called through a custom property
$$('body').append(html);
// Calling this method will initialize all uninitialized components in the page.
mdui.mutation();
If it is mdui.mutation()
The method passes in two parameters, which can be used to initialize the component you wrote yourself. The first parameter is the CSS selector, and the second parameter is the initialization function.
When calling mdui.mutation(selector, apiInit)
, the CSS selector will be bound to the initialization function, and $$(selector).each(apiInit)
will be executed > Call the initialization function.
When you call mdui.mutation()
next time, if the component corresponding to the CSS selector is not initialized, the initialization function will be called automatically.
If you need to initialize the components within the specified element, you can call $$(selector).mutation()
,This method initializes the uninitialized components in the selector and its child elements.
Theme color
Main color
Accent color