您還可以通過在Ember.View中設(shè)置tagName,classNames和classNameBindings屬性來自定義視圖的元素。
Ember.View.extend({ className:'NameofClass' classNameBindings:'AttributeName' tagName:'NameofTag' attributeBindings:'AttributeName' attrvalue:'AttributeValue' });
<!DOCTYPE html> <html> <head> <title>Emberjs Customizing a View's Element</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"> {{view "custom"}} </script> <script type="text/x-handlebars" data-template-name="custom"> <h1>Customizing the view</h1> <!-- using font tag by customizing its attribute in a sView --> <font>I am a Custom View my color is blue</font> </script> <script type="text/javascript"> App = Ember.Application.create(); // Customizing a view's elements: App.CustomView = Ember.View.extend({ //defining name of the template as 'custom' templateName: 'custom', tagName: 'font', //binding the 'color' attribute to the 'font' tag attributeBindings:['color'], //defining value for 'color' attribute 'color': "blue" }); </script> </body> </html>
讓我們執(zhí)行以下步驟,看看上面的代碼如何工作:
將上面的代碼保存在custm_view_elem.html文件中
在瀏覽器中打開此HTML文件。
更多建議: