我有一个问题,我正在使用Textext.js从数据库中列出用户,我正在使用带有自定义数据对象的标签({name: 'nameTag', id: 1})问题是我需要清理文本字段和带有“cleanFields”按钮的标签,我找不到办法。这是我的代码:
$("#myTextarea").textext({
plugins: 'tags prompt autocomplete',
prompt: 'Add one...',
ext: {
itemManager: {
items: [],
stringToItem: function (str) {
for (var i = 0; i < this.items.length; i++)
if (this.items[i].name == str) {
id = this.items[i].id;
break;
}
return { name: str, id: id }; //tags with custom data objects
},
itemToString: function (item) {
this.items.push(item);
return item.name;
},
compareItems: function (item1, item2) {
return item1.name == item2.name;
}
}
}
})
.bind('getSuggestions', function (e, data) {
var list = f_GetListTags() //this returns the list from the database
, textext = $(e.target).textext()[0],
query = (data ? data.query : '') || '';
$(this).trigger(
'setSuggestions',
{ result: textext.itemManager().filter(list, query) }
);
})
按钮:
$("#cleanFields").click(function () {
$('#myTextarea').val(''); //this cleans the text area
//but i also need to remove all tags :(
});
请帮我!:(