Select2不会加载其他结果

时间:2013-03-08 08:28:10

标签: javascript .net asp.net-mvc castle-monorail jquery-select2

我按以下方式设置选择:

$(function() {
        init_button_radio();
        $("#e6").select2({
            placeholder: "Cauta un cod de produs",
            minimumInputLength: 2,
            id: function(e) { return e.Id },
            ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
                url: "/photos/item",
                dataType: 'json',
                data: function(term, page) {
                    console.log({ query: term, page: page, page_limit: 10 });
                    return {
                        query: term, // search term
                        page: page,
                        page_limit: 10
                    };
                },
                results: function(data, page) {
                    var more = (page * 10) < data.total; // whether or not there are more results available
                    console.log(more);
                    // notice we return the value of more so Select2 knows if more results can be loaded
                    return { results: data.items, more: more };
                }
            },
            initSelection: function(element, callback) {
                // the input tag has a value attribute preloaded that points to a preselected movie's id
                // this function resolves that id attribute to an object that select2 can render
                // using its formatResult renderer - that way the movie name is shown preselected
                var id = $(element).val();
                if (id !== "") {
                    $.ajax("/photos/item/?itemId=" + id, {
                        dataType: "json"
                    }).done(function(data) { callback(data); });
                }
            },
            formatResult: itemFormatResult, // omitted for brevity, see the source of this page
            formatSelection: itemFormatSelection,  // omitted for brevity, see the source of this page
            dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
            escapeMarkup: function(m) { return m; } // we do not want to escape markup since we are displaying html in results
        });

在服务器端,它看起来像这样:

  [return: JSONReturnBinder]
        [AccessibleThrough(Verb.Get)]
        public object Item(string query,int page, int page_limit)
        {
            return new { items = this.items.GetItems(page_limit, page, query), total = this.items.CountItems(query) };
        }

服务器发送的项目符合预期,并由Select2解析:

  

{ “项”:[{ “的ItemKey”: “21D”, “名称”: “DERP”, “ID”:0, “价格”:60.6, “货币”: “EUR”, “数量”: 189, “DiscountCode”:2},{ “的ItemKey”: “21D”, “姓名”: “DERP”, “ID”:0, “价格”:60.6, “货币”: “EUR”, “数量”: 189, “DiscountCode”:2},{ “的ItemKey”: “21D”, “姓名”: “DERP”, “ID”:0, “价格”:60.6, “货币”: “EUR”, “数量”: 189, “DiscountCode”:2},{ “的ItemKey”: “21D”, “姓名”: “DERP”, “ID”:0, “价格”:60.6, “货币”: “EUR”, “数量”: 189, “DiscountCode”:2},{ “的ItemKey”: “21D”, “姓名”: “DERP”, “ID”:0, “价格”:60.6, “货币”: “EUR”, “数量”: 189, “DiscountCode”:2},{ “的ItemKey”: “21D”, “姓名”: “DERP”, “ID”:0, “价格”:60.6, “货币”: “EUR”, “数量”: 189, “DiscountCode”:2},{ “的ItemKey”: “21D”, “姓名”: “DERP”, “ID”:0, “价格”:60.6, “货币”: “EUR”, “数量”: 189, “DiscountCode”:2},{ “的ItemKey”: “21D”, “姓名”: “DERP”, “ID”:0, “价格”:60.6, “货币”: “EUR”, “数量”: 189, “DiscountCode”:2},{ “的ItemKey”: “21D”, “姓名”: “DERP”, “ID”:0, “价格”:60.6, “货币”: “EUR”, “数量”: 189, “DiscountCode”:2},{ “的ItemKey”: “21D”, “姓名”: “DERP”, “ID”:0, “价格”:60.6, “货币”: “EUR”, “数量” :189, “DiscountCode”:2}], “总”:70}

Select2知道它应该在我向下滚动时加载更多数据,但事实并非如此,即使我在文档之后配置了我的示例。我错过了什么吗?

0 个答案:

没有答案