1

jQuery プラグイン Tokeninput (マスター ブランチ) ( https://github.com/loopj/jquery-tokeninput ) には、タグを追加するための新しい機能があります。残念ながら、これまでのところ、この機能は Twitter で最もよく文書化されています: https://twitter.com/loopj/status/332249287062851585

onFreeTaggingAdd の使用方法を理解しようとしていますが、残念ながら私は jQuery と JavaScript の初心者です。

要するに、コールバックで API からの出力を受け取り、それをトークンボックスで使用したいと考えています。このようにして、タグ (小文字など) を変更し、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   
},
4

2 に答える 2

2

例のように、トークンをプログラムで追加および削除できます。

   $(document).ready(function() {
    $("#demo-input-plugin-methods").tokenInput("http://shell.loopj.com/tokeninput/tvshows.php");
                // Add a token programatically
                $("#plugin-methods-add").click(function () {
                    $("#demo-input-plugin-methods").tokenInput("add", {id: 999, name: "James was here"});
                    return false;
                });
// Remove a token programatically
            $("#plugin-methods-remove").click(function () {
                $("#demo-input-plugin-methods").tokenInput("remove", {name: "James was here"});
                return false;
            });
   });
于 2013-08-07T22:29:48.390 に答える