2010-10-26 79 views
1

有沒有辦法在YUI創建HTML標記,如:YUI 3 HTML模板

<div id={DivId}> 
<p class={pClass}> 
    <span class={spanClass}> {Content} </span> 
</p> 
</div> 

回答

2

如果我正確理解你的問題,Y.substitute可能是值得考慮的。

如果您還沒有看到,我建議您通過YUI 3 Sugar的視頻登錄YUI theaterY.substitute跳到22:27更多。

+1

還有Y.Lang.sub(),Y.substitute的更小,瘦的表親。 http://developer.yahoo.com/yui/3/api/Lang.html#method_sub – Tivac 2010-11-19 06:16:06

+1

由於此問題最初得到解答,YUI3還爲Handlebars模板添加了內置支持:http://yuilibrary.com/yui/docs/handlebars/ – alanning 2012-08-10 13:44:46

+1

YUI 3.8.0 [介紹Y.Template](http://www.yuiblog.com/blog/2012/12/12/yui-3-8-0-y-color-templates-and -more /),這比Handlebars快,但提供比Y.Lang.sub和Y.substitute更多的功能: – JayVee 2012-12-18 12:20:36

1

我做了同樣的事情....這是我用過的。

var resultFormatTemplate = 
     '<div class="result">{first_name}, {last_name}</div>'; 

function resultFormat(query, results) { 
    return Y.Array.map(results, function (result) { 
     var rep = result.raw; 

     return Y.Lang.sub(resultFormatTemplate, { 
      first_name : rep['First Name'], 
      last_name : rep['Last Name'] 
     }); 
    }); 
}; 

在Y.one標籤中,我使用resultFormatter : resultFormat來調用函數。