ms-click 二级联动赋值有错误
ms-click 二级联动赋值有错误,双击的话无法正确赋值,且浏览器报错 Uncaught TypeError: Cannot read property '1' of null
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.cur{color:red}
a{margin-left: 10px;}
</style>
<!--avalon版本为2.2.2-->
<script src="avalon2.js"></script>
<script>
var vm=avalon.define({
$id:'vm',
data:[
{
code:'1',
name:'初一年级',
classes:[
{
code:'11',
name:'初一(1)班'
}
]
},
{
code:'2',
name:'初二年级',
classes:[
{
code:'21',
name:'初二(1)班'
},
{
code:'22',
name:'初二(2)班'
},
{
code:'23',
name:'初二(3)班'
}
]
},
{
code:'3',
name:'初三年级',
classes:[]
},
{
code:'4',
name:'高一',
classes:[]
},
{
code:'5',
name:'高二',
classes:[]
},
{
code:'6',
name:'高三',
classes:[
{
code:'61',
name:'高三(1)班'
},
{
code:'62',
name:'高三(2)班'
},
{
code:'63',
name:'高三(3)班'
}
]
},
{
code:'7',
name:'大一',
classes:[
{
code:'71',
name:'大一(1)班'
},
{
code:'72',
name:'大一(2)班'
},
{
code:'73',
name:'大一(3)班'
}
]
},
],
gradeAndClassData:[],
classData:[],
//排序为第一个的年纪
gradeDataFirst:'',
gradeCodeCur:'',
init:function(){
//ajax 赋值
vm.gradeAndClassData=vm.data;
},
gradeClick:function(gradecode){
//给 classData赋值
for(var i=0;i<vm.gradeAndClassData.length;i++){
if(vm.gradeAndClassData[i].code==gradecode){
vm.classData=vm.gradeAndClassData[i].classes;
}
}
}
});
vm.init();
</script>
</head>
<body :controller="vm">
一级<br/>:<a ms-for="el in @gradeAndClassData" ms-click="@gradeClick(el.code,$event)">{{el.name}}</a><br/>
二级<br/>:<a ms-for="el in @classData">{{el.name}}</a>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)