jQuery 플러그인 Tokeninput (master branch) (https://github.com/loopj/jquery-tokeninput)에는 태그를 추가하는 새로운 기능이 있습니다. 불행히도 지금까지이 기능은 Twitter에서 가장 잘 설명되어 있습니다 : https://twitter.com/loopj/status/332249287062851585.jQuery Tokeninput 및 onFreeTaggingAdd 콜백
onFreeTaggingAdd를 사용하는 방법을 알아 내려고했지만 불행히도 저는 jQuery와 javascript 초보자입니다.
요약하면 내 API에서 출력을 가져 와서 tokenbox에서 사용하는 콜백을 원합니다. 이렇게하면 태그 (소문자 등)를 수정하고 ID를 추가 할 수 있습니다. api에서 제안한 정책이라면 다른 ID/태그로 대체 할 수도 있습니다.
아래 코드는 지금까지 참조하십시오. item = data를 설정하고 그 값을 반환하는 몇 가지 옵션을 시도했지만 성공하지 못했습니다. 어떤 도움을 주셔서 감사합니다!
onFreeTaggingAdd: function (item) {
$.post("../php/add_tagg_02.php", {tag: item, userid: "userid-dummy"})
.done(function(data, status, xhr) {
alert ("Your suggested new tag " + data.name + " is entered in the database and will be considered for future use.");
console.log(data.name); //returns the "new" name from the api
console.log(data.id); //returns the id provided by the api
})
return item; //returns the "old" name from the user input
},
이것은 실제로 작동 중입니다! 코드는 아주 깨끗합니다. 그러나 다음과 같이 제거하고 추가 할 필요가 없어야합니다. '\t onFreeTaggingAdd : function (item) { \t \t $ .post ("../ php/add_tagg_02.php", {tag : item, userid :. "사용자 ID-더미"}) \t \t되는 .done (기능 (데이터, 상태, XHR) { \t \t 경고 ("메시지"); \t \t $ ("# 태그") tokenInput는 ("제거" {이름 : "쓰레기"}); \t \t $ ("# 태그") tokenInput는 ("추가", {ID : data.id, 이름 : data.name}); \t \t}) \t \t. 반환 "쓰레기"; \t} ' – moltubakk
이 작업을 처리 할 수있는 경우 스크립트'add_tagg_02.php '를 사용하여 태그를 직접 변경할 수 있기 때문에 옳다고 생각합니다. – kelsar