通過將鏈接文本指定為輔助程序的第一個參數(shù),link-to助手將用作內(nèi)聯(lián)形式。
Click here for {{#link-to 'link1'}}more{{/link-to}}, info of {{link-to 'link text' 'link2'}}.
<!DOCTYPE html> <html> <head> <title>Emberjs Template Inline Helper</title> <!-- CDN's --> <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.1/handlebars.min.js"></script> <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.10.0/ember.min.js"></script> <script src="https://builds.emberjs.com/tags/v1.10.0-beta.3/ember-template-compiler.js"></script> <script src="https://builds.emberjs.com/release/ember.debug.js"></script> <script src="https://builds.emberjs.com/beta/ember-data.js"></script> </head> <body> <script type="text/x-handlebars"> Click for the {{#link-to 'info'}}Fruits{{/link-to}} information, for the documentation {{link-to 'Click for records' 'records'}}. {{outlet}} </script> <script type="text/x-handlebars" data-template-name="info"> <p>Some Fruits</p> <ul> <li>Orange</li> <li>Banana</li> </ul> </script> <script type="text/x-handlebars" data-template-name="records"> <p>Some Records</p> <ul> <li>Orange.doc</li> <li>Banana.doc</li> </ul> </script> <script type="text/javascript"> App = Ember.Application.create(); //mapping the router for different template App.Router.map(function() { //link to the info resource this.resource('info'); //link to the records resource this.resource('records'); }); </script> </body> </html>
讓我們執(zhí)行以下步驟,看看上面的代碼如何工作:
將上面的代碼保存在temp_link_inline_helper.html文件中
在瀏覽器中打開此HTML文件。
更多建議: