【发布时间】:2019-06-05 05:08:23
【问题描述】:
我想从 ajax 响应创建数组。我从 ajax 获取数组,我必须为芯片创建动态数据 materializecss autocomplete
var tag = '';
$(document).on('keyup', '.tags', function() {
var _this = $(this).val();
if(_this.length > 1) {
$.ajax({
url: '/story/searchTags',
type: 'POST',
dataType: 'JSON',
data: {
tag: _this
},
success: function(tags) {
tag = tags;
}
});
}
});
$('.chips-placeholder').chips({
placeholder: lang_('Your tag'),
secondaryPlaceholder: '+ tag',
autocompleteOptions: {
// I need data like this from response
data: {
'Google', null
'Googol', null
},
limit: 5,
minLength: 2
}
});
<div class="chips chips-placeholder chips-autocomplete input-field" style="background:#fff">
<input class="input tags" placeholder="tag" autocomplete="off" />
</div>
最后,感谢@Vel 找到正确答案。 jsfiddle - work code
【问题讨论】:
-
你的代码和你的解释与
data不同 -
@M.Hemant 哪里不一样?