159 Star 734 Fork 192

yoby / weui

 / 详情

如何动态从语文老师换成数学老师

Done
Opened this issue  
2021-04-07 21:21

代码如下:
var arrTeacher=['陈老师','孙老师'];
var arrSubject=[{title:'语文',value:57},{title:'数学',value:17}];

$("#teacher").select({
title: "选择教师",
items: arrTeacher,
onChange: function(d) {
console.log(this, d);
},
onClose: function() {
console.log("close");
},
onOpen: function() {
console.log("open");
},
});
$("#subject").select({
title: "选择学科",
items: arrSubject,
onChange: function(d) {
//console.log(this, d);
axios.get('<%=basePath%>/EntWxGetTeacher?id='+d.values) //也可以直接拼接在url
.then(function(rs){
console.log(rs)
//document.querySelector("#d").innerHTML = rs.data.data.name;
arrTeacher=rs.data;
$("#teacher").select({title:"选择教师",items:arrTeacher});
alert('请求成功'); //数据在rs.data中 状态rs.status=200
}).catch(function(e){
console.log(e);
//alert('请求失败'); //数据在e.data中 状态e.status=200
});
},

Comments (1)

shihuagluo created任务
shihuagluo set related repository to yoby/weui
Expand operation logs

你肯定没注意页面里面注释 有个update就可以实现这种联动选择
$("#job").select({
title: "喜欢的美女",
items: ['柳岩','赵丽颖'],
onChange: function(d) {
$.post("/ver",{value:d.values},function(res){
//console.log(res)
$("#mobile").select("update", { items: [{title:'语文',value:57},{title:'数学',value:17}]})
},'json');
},
onClose: function() {
console.log("close");
},
onOpen: function() {
console.log("open");
},
});
我写了个例子在weui上你测试看

yoby changed issue state from 待办的 to 已完成

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(2)
616004 yoby 1578929281
JavaScript
1
https://git.oschina.net/yoby/weui.git
git@git.oschina.net:yoby/weui.git
yoby
weui
weui

Search

182229 41614e54 1850385 182230 7885ed45 1850385