Class yii\jui\AutoComplete [ 新手入门 ]
AutoComplete实现了基本功能,根据输入查到ID,但是想要得到更丰富的下拉自定义内容
<?= $form->field($model, 'smid')->widget('yii\jui\AutoComplete',[
'options'=>['class'=>'form-control'],
'clientOptions'=>[
'source'=>app\models\TrainMember::find()->select(['id'])->column()
//'source'=>app\models\TrainMember::find()->select(['id,name'])->all()
]
]) ?>
手册里有的就是这些,转到JqueryUI去,都是JS代码:
<script>
$(function() {
var projects = [
{
value: "jqueryvalue",
label: "jQuerylabel",
desc: "descthe write less, do more, JavaScript library",
icon: "iconjquery_32x32.png"
},
{
value: "jquery-ui",
label: "jQuery UI",
desc: "the official user interface library for jQuery",
icon: "jqueryui_32x32.png"
},
{
value: "sizzlejs",
label: "Sizzle JS",
desc: "a pure-JavaScript CSS selector engine",
icon: "sizzlejs_32x32.png"
}
];
$( "#project" ).autocomplete({
minLength: 0,
source: projects,
focus: function( event, ui ) {
$( "#project" ).val( ui.item.label );
return false;
},
select: function( event, ui ) {
$( "#project" ).val( ui.item.label );
$( "#project-id" ).val( ui.item.value );
$( "#project-description" ).html( ui.item.desc );
$( "#project-icon" ).attr( "src", "static/images/" + ui.item.icon );
return false;
}
})
//想实现下面段JS的代码,得到想要的
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li>" )
.append( "<a>" + item.label + "<br>" + item.desc + "</a>" )
.appendTo( ul );
};
});
</script>
搞搞的传奇
注册时间:2015-02-24
最后登录:2020-06-04
在线时长:24小时46分
最后登录:2020-06-04
在线时长:24小时46分
- 粉丝8
- 金钱5
- 威望10
- 积分345