layui框架form.on事件中如何用this获取父元素方法

layui框架不错,但是因为它渲染了很多组件,比如select下拉菜单(美化),导致了select的事件必须要写form.on(‘select(type)’, function(data){… 来获取,涉及到一些稍微复杂一点的情况,容易找不到北,比如一般事件中默认有一个this指针,但是form.on中没有,经过一番努力最后还是找到了。

layui框架form.on事件中如何用this获取父元素方法

核心代码是 $(data.othis).parents('.layui-item').find("select[name='ProjectType[]']").html(html);

完整代码

form.on('select(type)', function(data){

console.log(data);

var z=data.value;
if(z==null || z=="")
{
var h="";
$(data.othis).parents('.layui-item').find("select[name='ProjectType[]']").html(h);
//layui.$("select[name='ProjectType[]']").html(h);
form.render('select');
return false;
}
var arr={'code':z};
layui.$.ajax({
type: 'POST',
dataType: 'json',
url: '/index.php/competition2022/matchTypeList',
data:arr
}).done(function (result) {
if(result!=null)
{
var html="";
layui.$.each(result,function(n,value){
html +="";
});
$(data.othis).parents('.layui-item').find("select[name='ProjectType[]']").html(html);
//layui.$("select[name='ProjectType[]']").html(html);
form.render('select');
}
});
});
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章