简体   繁体   中英

Dojo FilteringSelect - Full JSON Response Data Not Visible

Trying to convert a jQuery autocomplete to a Dojo version. Initally followed this advice ( Textbox autocomplete with DOJO ), but switched to JsonRest .

When entering input (eg. "th") i can see the proper JSON response in the console, [{"id":"thing1","label":"thing1"},{"id":"thing2","label":"thing2"},{"id":"thing3","label":"thing3"}] , but no list of options appears on screen. When the focus leaves the target input , it's always autocompleted with the first element ("thing1" in this example).

// DOM Element
<div id="things"></div>

// Get data
var jsonStore = new JsonRest  ({  
    target: "/ajax_suggest/autocomplete"
});

// Autocomplete attempt
ready(function(){

    var thingSearch = new FilteringSelect({
        id: "things",
        name: "things",
        store: jsonStore,
        placeHolder: "Search the things...",
        searchAttr: "term",
        onSearch: function(results, query) {
            console.log(JSON.stringify(results));
        }                   
    },"things");

    thingSearch.startup();

});

So, at this point, i'm satisfied that the data is arriving correctly after the input data has been processed, and ultimately, the contents of the input are "autocompleted", but i'm missing something, or haven't grasped something, pretty fundamental here to get the full response to be displayed!

您有searchAttr: "term" ,但是“ term”不在您的JsonRest存储中-我想您希望将其作为searchAttr: "label"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM