backbone.js视图属性

Backbone.js属性方法指定属性的哈希,该哈希包含视图el上的HTML DOM元素属性(id,class,data-properties等),或返回此类哈希的函数。
句法:

view.attributes

让我们举个例子。
请参阅以下示例:
< !DOCTYPE html> < head> < title>View Attributes Example< /title> < script src="http://img.readke.com/220416/064R5MN-0.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/064R52639-1.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/064R555Y-2.jpg" type="text/javascript">< /script> < /head> < body> < div id="myapp">< /div> < script type="text/javascript"> var MyModel = Backbone.Model.extend({ defaults: { name: "John Davison" } }); var ViewDemo = Backbone.View.extend({initialize: function () { document.write("View is initialized..."+"< br>"); document.write("My site name is: ", this.model.get("Site")+"< br>"); document.write("My tag name is: ", this.tagName+"< br>"); document.write("My class name is: ", this.className); }, }); $(function () { var mymodel = new MyModel({ Site: "srcmini" }); var myview = new ViewDemo({ model: mymodel, tagName: "mytag", className: "myclass"}); < /script> < /body> < /html>

输出:
【backbone.js视图属性】将上面的代码保存在attributes.html文件中,然后在新的浏览器中打开该文件。
backbone.js视图属性

文章图片

    推荐阅读