locked
How bind RadDropDown to a complex Json string RRS feed

  • Question

  • User945338570 posted

    hi, I have following JSON string but unable to bind it :

    JSON string : 

    var result ="{\"GroupDispositions\":[{\"Code\":\"C\",\"Description\":\"CONTACTED\"},{\"Code\":\"NC\",\"Description\":\"NOT CONTACTED\"}],\"Response\":[{\"ResultCode\":\"0\",\"ResultString\":\"Pass\"}]}";


    Here is my Code:

    function OnSuccess_FillDispositions(result) {
                try {
                    if (result == null)
                        return;
                    var items = result.d || result;
                    var combo = $find('<%=cmbMainDisposition.ClientID %>');
                    var combosubsub = $find("<%= cmbSubSubDisposition.ClientID %>");
                    // alert(combo);
                    if (combo != null) {
                        combo.clearItems();
                        combosubsub.clearItems();
                        combosubsub.clearSelection();
                       
                        for (var rowIndex = 0; rowIndex < result.length; rowIndex++) {
                            var row = result[rowIndex];
                            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
                            comboItem.set_value(row.Code);
                            comboItem.set_text(row.Description);
                            comboItem.get_attributes().setAttribute("Code", row.Code);
                            combo.get_items().add(comboItem);
                        }
                    }
                    combo.get_items().getItem(0).select();
    
    
                }

    Please help!

    Monday, November 5, 2018 10:38 AM

Answers

  • User2103319870 posted

    following JSON string but unable to bind it :

    Try parsing the Json to javascript object and then loop thorugh GroupDispostion array to access code and descriptions

    Try with below code

    function OnSuccess_FillDispositions(result) {
                        try {
                            if (result == null)
                                return;
                            var items = result.d || result;
                            var combo = $find('<%=cmbMainDisposition.ClientID %>');
                            var combosubsub = $find("<%= cmbSubSubDisposition.ClientID %>");
                            // alert(combo);
                            if (combo != null) {
                                combo.clearItems();
                                combosubsub.clearItems();
                                combosubsub.clearSelection();
                                //Parse the Json string
                                var parsedResult = JSON.parse(result);
                                //Loop through GroupDispositions and assign the value
                                for (var rowIndex = 0; rowIndex <= parsedResult.GroupDispositions.length; rowIndex++) {
                                    var row = result[rowIndex];
                                    var comboItem = new Telerik.Web.UI.RadComboBoxItem();
                                    comboItem.set_value(parsedResult.GroupDispositions[rowIndex].Code);
                                    comboItem.set_text(parsedResult.GroupDispositions[rowIndex].Description);
                                    comboItem.get_attributes().setAttribute("Code", parsedResult.GroupDispositions[rowIndex].Code);
                                    combo.get_items().add(comboItem);
                                }
                            }
                            combo.get_items().getItem(0).select();
                        }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 6, 2018 6:53 PM