我有一個自動完成功能的文本框。我的代碼是值codeigniter控制器查看和顯示內部JavaScript變量作爲數組
<script>
$(function() {
var items = [ 'France', 'Italy', 'Malta', 'England',
'Australia', 'Spain', 'Scotland' ];
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$("#skills")
.autocomplete({
minLength: 0,
source: function(request, response) {
response($.ui.autocomplete.filter(
items, extractLast(request.term)));
},
focus: function() {
return false;
},
select: function(event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
return false;
}
});
});
</script>
上面的代碼工作正常。現在的問題是,我想顯示來自數據庫的值而不是var items = [ 'France', 'Italy', 'Malta', 'England', 'Australia', 'Spain', 'Scotland' ];
。我想更改變量item
中的值。
我笨控制器代碼,
$data['skills'] = $this->workdone->getAllSkills();
$this->load->view($page, $data);
我的HTML代碼,
<input type="text" name="skills" id="skills">
我已經嘗試了很多。有沒有解決辦法。
概念:VAR項目= <=的print_r(技能); ?>; – WRDev