0
我使用的引導中,我有一個輸入的複選框這樣的:流星加載JavaScript函數DOM後載入
<input type="checkbox" id="toggle" name="toggle">
而且我使用Bootstrap Switch使用它們的功能將其轉換成一個開關:
Meteor.startup(function() {
$("[name='toggle']").bootstrapSwitch();
});
但是,問題是交換機只加載一半的時間。我認爲這是因爲該函數在複選框加載到DOM之前被調用。我認爲把它放入Meteor啓動函數可以修復它,但它不會。如何確保在加載複選框後加載此開關?我試過Template.body.onRendered
,它也沒有工作。
嘗試使用'Template.body.onCreated' – chackerian
@jswny您想使用'Template.X.onRendered',其中'X'是複選框的直接父模板。這應該適用於所有情況,除非元素是有條件呈現的(在這種情況下,更多技巧是必要的,我會指出你的相關問題)。 –
@chackerian和David Weldon我已經嘗試了這兩件事,但都沒有成功。 –