grootJs的属性绑定指令
index6.html
绑定文本text
gt-text="{属性名}"
绑定标签属性attr
gt-attr="vm属性名称(标签属性,value表达式)" 如 gt-attr="uid(id,'view'+value)"
绑定标签属性css
gt-css="vm属性名称(标签属性,value表达式)"
同attr
绑定标签属性class
1.gt-class="vm属性名称(class名称:value表达式,class名称:value表达式,class名称:value表达式...)"
class 的value表达式比较特殊 value表达式为true 就绑定对应的属性 为fale 就不绑定对应的属性
2.gt-class-属性名="class名称:value表达式,class名称:value表达式,class名称:value表达式..." (可以绑定多个)
<html> <head> <title>grootJs的属性绑定指令</title> <script src="jquery-1.11.2.min.js"></script> <script src="groot.js"></script> <style> .back0 { background-color: coral; } .back1 { background-color: forestgreen; } </style> </head> <body> <div gt-view="myview"> <div gt-css="c(color,value)">你好</div> <input gt-attr="uid(id,'view'+value)" type="text" gt-value-change="say"><span gt-text="{uid}+':说'+{say}"></span> <div> <ul gt-each="list"> <li gt-class="$index(back0:value % 2 ==0,back1:value % 2==1)"><span gt-text="{$index}+1"></span><span>姓名:</span><span gt-text="{name}"></span>---<span>性别:</span><span gt-text="{sex}"></span></li> </ul> </div> </div> </body> </html> <script> groot.view("myview", function (vm, ve) { vm.list = [ {"name": "张三", "sex": "男"} , {"name": "李四", "sex": "男"} , {"name": "王五", "sex": "男"} ]; vm.uid = "123"; vm.say = "word"; vm.c = "red" }) </script>