1

テキスト フィールドのビューでjQuery オート コンプリート プラグインを使用しています。単一選択は完全に機能します。

複数の選択を組み込んでいますが、何らかの理由で複数の値を選択すると、前の選択が上書きされます。

jQuery Plugin Tutorialsの例に従っています。

 $("#ServiceEntryFilter_System").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: serviceentrySystemURL, type: "POST", dataType: "json",
                minLength: 0,
                data: { searchText: extractLast(request.term), maxResult: 100, instrumenttype: userroleid },
                success: function (data) {
                    response($.map(data, function (item) {
                        return { value: item }
                    }))
                }
            })
        },
        focus: function () {
            // prevent value inserted on focus
            return false;
        },
        select: function (event, ui) {
            var terms = split(this.value);

            // remove the current input

            terms.pop();

            // add the selected item

            terms.push(ui.item.value);

            // add placeholder to get the comma-and-space at the end

            terms.push("");

            this.value = terms.join(", ");

            return false;


        }
    });

    function split(val) {

        return val.split(/,\s*/);

    }

    function extractLast(term) {

        return split(term).pop();

    }


[HttpPost]
public JsonResult FindSystem(string searchText, int maxResult, string instrumenttype)
{
    int UserRoleID = AccessHelper.GetUserRoleID(User.Identity.Name);
    var result = RunLog.Domain.Lists.GlobalList.GetInstrumentSystem(searchText, maxResult, instrumenttype);

    return Json(result);
}
4

1 に答える 1

0

これがあなたが探しているものかどうかは 100% わかりませんが、選択イベントはあなたが望むものではありません。関数を実行した後に値を上書きしているようです。

これを試してみたところ、配列に値が追加されたように見えました:(フォーカスに変更しただけです)

            focus: function(event, ui){
            var terms = this.value.split(", ");

            // remove the current input

            terms.pop();

            // add the selected item

            terms.push(ui.item.value);

            // add placeholder to get the comma-and-space at the end

            terms.push("");

            this.value = terms.join(", ");

            return false;


        }
于 2013-06-24T19:52:31.643 に答える