2016-07-21 38 views
0

如何使用jQuery從.mustache文件讀取DIV ID?canjs使用jquery和小鬍子

例如 asdf.mustache

<div class="draggable"> 
    <p>drag this here</p> 
</div> 

adminControl.js

define(['jQuery', 'can', 'ctbConfig','labelsConfig'], function(jQuery, can,  ctbConfig,labelsConfig) { 
$(".draggable").draggable(); 
} 

這裏$( 「拖動」)可拖動()。不管用。

+0

模板是否呈現? –

回答

0

您可以使用jQuery filter()訪問的呈現模板元素

var template = '<div class="draggable"> <p>drag this here</p></div>'; 
var html = Mustache.render(template, {}); 
// Use filter to get the element .draggable 
$(html).filter('.draggable').draggable(); 

我不認爲你可以調用.draggable();直到它被呈現給DOM。

查看更多about filter()here