This is a migrated thread and some comments may be shown as answers.

JSONP remote data with call function

1 Answer 130 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Karel
Top achievements
Rank 1
Karel asked on 23 Sep 2012, 04:47 PM
Hi,

I have a problem with data source for autocomplete. I get data from remote service via callback function which fills global json object. I need to use this object as a datasource but I don't know how to refresh datasource because I don't have transport.read method. Is there a way how to refresh datasource somehow?

This code could help to clafiry:

YAHOOsuggest={ResultSet:{Query:'',Result:[]}};<br>
YAHOO = { Finance: { SymbolSuggest: { ssCallback: function (jsn) { YAHOOsuggest = jsn; return (jsn); } } } };
 
function InitializeStockInput() {
    $("#stockInput").kendoAutoComplete({<br>
        dataSource: new kendo.data.DataSource({
            data: YAHOOsuggest.ResultSet.Result,
            type: "json"
        }),
        placeholder: "Select stock...",
        minLength: 1,
        dataTextField: "name",
        dataValueField: "symbol"
    });
}
 
function StockInputChanged(sender) {
    var url='http://d.yimg.com/autoc.finance.yahoo.com/autoc?query='+ sender.value +'&callback=YAHOO.Finance.SymbolSuggest.ssCallback';
    helper(url);
}
 
 
function helper(url) {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;
    script.id = 'helperScript';
    script.onload = cleaner;
    head.appendChild(script);
}
 
 
function cleaner() {
    $('#helperScript').remove();
}

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 27 Sep 2012, 07:24 AM
Hello Karel,

If you have already have loaded the data without the DataSource, you can use its data method to set it. e.g.

var autoComplete = ("#stockInput").data("kendoAutoComplete");
autoComplete.dataSource.data(myDataArray);
Also, note that the AutoComplete does not support a value field and if you need to use separate fields for the text and value you should use ComboBox instead. Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
AutoComplete
Asked by
Karel
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or