老师讲解一下
.on('reloadOptions',function(){
var method = $(this).attr('data-search');
var args = $(this).attr('data-where').split(',');
var data = AjaxRemoteGetData[ method ].apply( this, args );
var select = $(this);me
select.find('option').remove();
$.each( data , function(i,item){
var el = $('<option value="'+item+'">'+item+'</option>');
select.append(el);
});
});
selects.eq(0).triggerHandler('reloadOptions');
}
24
收起
正在回答 回答被采纳积分+1
2回答
好帮手慕言
2020-08-02 09:51:50
同学你好,同学的代码中多了me
整体可以参考下方:
// 绑定自定义reloadOptions事件 .on('reloadOptions', function() { // 获取select的data-search属性值 var method = $(this).attr('data-search'); // 获取select的data-where属性值并使用逗号分隔 var args = $(this).attr('data-where').split(','); // 从通过参数从data.js文件中获取数据 var data = AjaxRemoteGetData[method].apply(this, args); var select = $(this); // 将原有的option移除 select.find('option').remove(); // 将获取的指定数据遍历,和option标签拼接,重新添加到select中 $.each(data, function(i, item) { var el = $('<option value="' + item + '">' + item + '</option>'); select.append(el); }); }); // 默认第一个的select触发更新事件 selects.eq(0).triggerHandler('reloadOptions');
如果我的回答帮到了你,欢迎采纳,祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星