2014-05-08 44 views
1

我在我的應用程序中使用了Marionette,但是我發現它生成了許多空的文本節點和空白標記。就像這樣:如何避免在Marionette中生成空的文本節點?

enter image description here

如何避免呢?

+0

看起來像您的模板引擎呈現空值,例如null或undefined。如果它是一個數組,請使用_.compact()首先刪除空元素。 –

回答

0

通常,您可以在視圖上使用tagName屬性來生成該類型的html元素。將tagName設置爲「li」或「table」或任何可以在您的html中生成外部標記而不是「div」的內容。

然而,從生成的html的外觀來看,您的模板似乎可能存在一些錯誤。木偶不應該生成額外的「div」,當然不是空白的「」。

+0

你認爲它可能是由jQueryUI生成的嗎?你可以看到我使用jQuery對話框。我用TypeScript和Dust開發它。 – WangHongjian

+0

快速瀏覽一下使用TypeScript和Marionette的博客。此博客使用Marionette模板引擎,而不是灰塵 - 因此它可能與粉塵有關。 http://blorkfish.wordpress.com/2014/03/22/typescript-using-backbone-marionette-and-rest-webapi-part-1/ – blorkfish

0

調試完所有相關資源後,我發現這個問題是由dustjs(文件名爲backbone.marionette.dust.js)引起的。

Backbone.Marionette.Renderer.render = function (template, data) { 
    var html; 
    // Template must be compiled and in the dust cache. Recommend pre-compiling 
    // and loading the templates as scripts at app start. 
    dust.render(template, data, function (err, out) { 
    html = out; 
    }); 
    html = html.trim();//This line was added by me. 
    return html; 
}; 

在該行'html = html.trim();'後面不會出現空的文本節點。加入。

相關問題