backbone.js
के साथ बनाए गए ऐप के लिए underscore.js
टेम्पलेट के अंदर चर सेट अप करने के लिए कैसे? मैं सिर्फ पुन: प्रयोज्य संसाधित तार बनाना चाहता हूं। साथ ही, underscore.js
के अंतर्निहित कार्यों जैसे _.escape
का उपयोग उन चरों को संसाधित करने के लिए किया जा सकता है?underscore.js टेम्पलेट के अंदर चर
<script type="text/html" id="templateresults">
<p><%= encodeURIComponent(title) %></p> // this works
// try 1:
var encodedTitle = encodeURIComponent(title); // shows up as regular text
<p>'+encodedTitle+'</p> // this doesn't work and shows up as regular text
// try 2:
<% var encodedTitle = encodeURIComponent(title); %> // nothing shows up
<p><% '+encodedTitle+' %></p> // nothing shows up
</script>
title
एक JSON आइटम (टेक्स्ट स्ट्रिंग) है।
एन्कोडेड उत्पादन: This%20is%20a%20Sample%20Title
नियमित उत्पादन: This is a Sample Title
मीठे! यह काम करता हैं। धन्यवाद! – Steve