jquery选择2个未格式化的选项

时间:2017-03-24 14:27:54

标签: jquery ajax jquery-ui select2

我有这种格式的结果,无法获得加载的选项:请你帮我:结果方法应该是什么样的?

          [{"id":2,"name":512843},{"id":2,"name":512844},
           {"id":2,"name":512847},{"id":2,"name":512874},
           {"id":2,"name":512875},{"id":2,"name":512880},
           {"id":2,"name":512884},{"id":2,"name":512886},
           {"id":2,"name":512887},{"id":2,"name":512888},
           {"id":2,"name":512892},{"id":2,"name":512896},
           {"id":2,"name":512907},{"id":2,"name":512910},
           {"id":2,"name":512911},{"id":2,"name":512913},
           {"id":2,"name":512914},{"id":2,"name":512917},
           {"id":2,"name":512925},{"id":2,"name":512930},
           {"id":2,"name":512931},{"id":2,"name":512935}]

它只是说加载失败

        processResults: function (data) {
            return {
                results: $.map(data.items, function (item) {
                    return {
                        text: item.name,
                        id: item.id
                    }
                })
            };
        }

1 个答案:

答案 0 :(得分:0)

我可以找到答案,我们应该从json输出

results = [{"id":2,"name":512847},{"id":2,"name":512874},
           {"id":2,"name":512875},{"id":2,"name":512880},
           {"id":2,"name":512884},{"id":2,"name":512886},
           {"id":2,"name":512887},{"id":2,"name":512888},
           {"id":2,"name":512892},{"id":2,"name":512896},
           {"id":2,"name":512907},{"id":2,"name":512910},
           {"id":2,"name":512911},{"id":2,"name":512913},
           {"id":2,"name":512914},{"id":2,"name":512917},
           {"id":2,"name":512925},{"id":2,"name":512930},
           {"id":2,"name":512931},{"id":2,"name":512935}]

当我拥有它时,一切都已到位并且select2开始工作了!