使用selectize.js,我试图将select字段的名称属性传递给selectize加载方法,但无法解决。
到目前为止已尝试:
。
<select name="combo1" class="fa_lookup" placeholder="Type to search..">
<option value="4">val</option>
</select>
<select name="combo2" class="fa_lookup" placeholder="Type to search...">
<option value="2">val2</option>
</select>
<script>
//somehow pass the name of the field - how?
$('.fa_lookup').selectize({
valueField: 'ID', labelField: 'name', searchField: 'name',
create: false,
load: function(query, callback) {
console.log($(this).parent()); // <= No luck
if (query.length < 2) return callback();
$.ajax({
url: 'getnames.php',
type: 'GET',
dataType: 'json',
data: {
name: query,
},
error: function() {
callback();
},
success: function(res) {
callback(res);
}
});
}
});
</script>