在页面加载我有一个令牌输入,即
  $('.txtWard').tokenInput(ward, {
                                        theme: 'facebook',
                                        allowCustomEntry: true,
                                        preventDuplicates: true,
                                        tokenDelimiter: '*',
                                        searchingText: 'Searching...'
                                    });
但问题是当我单击另一个按钮时,我想将项目预填充到此令牌输入文本框。当我使用下面的代码时,文本框复制为另一个文本框。
  $(document).ready(function () {
            $('.txtWard').tokenInput(ward, {
                theme: 'facebook',
                allowCustomEntry: true,
                preventDuplicates: true,
                tokenDelimiter: '*',
                searchingText: 'Searching...'
            });
            $('#btnGet').click(function () {
                var prepopulateWards = new Array();
                $.ajax({
                    type: "POST",
                    url: "FetchWard",
                    data: JSON.stringify({ patientNo: $('#txtPatientNo').val(), locale: 'en-US' }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        for (var j = 0; j < result.wards.length; j++) {
                            prepopulateWards.push({ id: result.wards[j].Code, name: result.wards[j].ward });
                        }
                    }
                });
                $('.txtWard').tokenInput(ward, {
                    theme: 'facebook',
                    allowCustomEntry: true,
                    preventDuplicates: true,
                    tokenDelimiter: '*',
                    searchingText: 'Searching...',
                    prePopulateFromValue: true,
                    prePopulate: prepopulateWards
                });
            });
        });