admin管理员组文章数量:1318150
I'm using selectize.js:
- I have a number of similar select boxes
- Options are loaded dynamically from the server, during
load()
- The query made during
.load()
is unique to each select box. Eg, I'd like to have a.load()
hit a different URL based on some property of the select box (eg,data-someproperty
).
How can I do that? Code right now is almost identical to the Remote Source example from the Selectize docs.
$('.select-repo').selectize({
valueField: 'url',
labelField: 'name',
searchField: 'name',
create: false,
...
load: function(query, callback) {
if (!query.length) return callback();
$.ajax({
url: '/' + encodeURIComponent(query),
type: 'GET',
error: function() {
callback();
},
success: function(res) {
callback(res.repositories.slice(0, 10));
}
});
}
});
I tried checking out this
during .load() but I can't see any reference to the original element.
I'm using selectize.js:
- I have a number of similar select boxes
- Options are loaded dynamically from the server, during
load()
- The query made during
.load()
is unique to each select box. Eg, I'd like to have a.load()
hit a different URL based on some property of the select box (eg,data-someproperty
).
How can I do that? Code right now is almost identical to the Remote Source example from the Selectize docs.
$('.select-repo').selectize({
valueField: 'url',
labelField: 'name',
searchField: 'name',
create: false,
...
load: function(query, callback) {
if (!query.length) return callback();
$.ajax({
url: 'https://api.github./legacy/repos/search/' + encodeURIComponent(query),
type: 'GET',
error: function() {
callback();
},
success: function(res) {
callback(res.repositories.slice(0, 10));
}
});
}
});
I tried checking out this
during .load() but I can't see any reference to the original element.
1 Answer
Reset to default 10Found it:
Inside load(), access:
this.$input
To get a JQuery selection with the <select>
element.
this.$input.data('whatever')
Would return data-whatever
from the select
版权声明:本文标题:javascript - selectize.js - how can reference some property of the select element during load()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742043971a2417675.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论