绑定数组

index4.html

<html>
<head>
<title>绑定数组</title>
<script src="jquery-1.11.2.min.js"></script>
<script src="groot.js"></script>
</head>
<body>
<div gt-view="myview">
<input type="button" gt-click="push" value="添加数组"/>
<input type="button" gt-click="pop" value="删除数组pop"/>
<input type="button" gt-click="chObject" value="改变数组某一项"/>
<input type="button" gt-click="splice" value="删除数组splice"/>
<input type="button" gt-click="insert" value="插入"/>
<input type="button" gt-click="chList" value="给整个数组重新赋值"/>
<ul gt-each="list">
<li gt-attr="$index(id,value +1)"><span gt-text="{$index}+1"></span><span>姓名:</span><span
gt-text="{name}"></span>---<span>性别:</span><span
gt-text="{sex}"></span><input
type="text" gt-value-change="name"/></li>
</ul>
</div>
</body>
</html>
<script>
groot.view("myview", function (vm, ve) {
vm.list = [
{"name": "张三", "sex": "男"}
];
ve.push = function () {
vm.listpush({"name": "张三", "sex": "男"});
}
ve.pop = function () {
vm.listpop();
}
ve.splice = function () {
vm.listsplice(1, 1);
}
ve.insert = function () {
vm.listsplice(1, 0, {"name": "李四", "sex": "男"});
}
ve.chObject = function () {
vm.list[1] = {"name": "王五", "sex": "男"};
vm.listRender(1);
}
ve.chList = function () {
vm.list=[
{"name": "大盗", "sex": "男"}
,{"name": "乔三", "sex": "男"}
];
vm.listRender();
}
})
</script>

绑定数组这里,要注意:

1.数组的render方法不同于对象和属性

2.数字的操作push pop shift unshift splice contact 操作 不只直接操作数组 而是数组所在对象上生成对应这个数组的操作方法 如 listpush 方法 就是给list数组添加新项

posted @ 2014-06-09 21:25  吹鱼算法  阅读(600)  评论(0编辑  收藏  举报