[CLOSED] Assigning store data from javascript not working

  1. #1

    [CLOSED] Assigning store data from javascript not working

    Hi i would like to assign the data property of a store from Javascript. But the Code is not working as expected. see code below.


    javascript
     
    var GetDatabaseSettingResponse = function () {
        jQuery.ajax(
             {
                 url: "/DatabaseConfiguration/DatabaseConfiguration/GetDatabaseSettingResponse",
                 traditional: true,
                 type: 'POST',
                 contentType: "application/json; charset=utf-8",
                 success: function (result) {
                     var resultData = jQuery.parseJSON(result);
                     if (resultData.error.length == 0) {
                         Ext.MessageBox.hide();
                         DatabaseTypesStore.data = resultData.result.DatabaseServerTypes;
                     }
                     else {
                         Ext.MessageBox.hide();
                         alert(resultData.error);
                     }
                 }
             });
    }
    Store

    <ext:Store ID="DatabaseTypesStore" runat="server"   >
                    <Reader>
                    <ext:JsonReader IDProperty="DatabaseType" Root="data" >
                        <Fields>
                            <ext:RecordField Name="DisplayName" />
                            <ext:RecordField Name="DatabaseType" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>   
                <Listeners>
                </Listeners>          
            </ext:Store>
    The combo box that consumes the store

    <ext:ComboBox ID="cmbDatabaseType"
                                        runat="server" 
                                        FieldLabel="Database type"
                                        AnchorHorizontal="100%" Editable="false"  
                                        EmptyText="Select Database Type" 
                                        StoreID="DatabaseTypesStore"  
                                        DisplayField="DisplayName" 
                                        Mode="Local"
                                        ValueField="DatabaseType">   
                               </ext:ComboBox>
    the controller code that generate the objects

    public string GetDatabaseSettingResponse()
           {
               JavaScriptAjaxResult result = new JavaScriptAjaxResult();
                      DatabaseServerTypesResponse response = new DatabaseServerTypesResponse ();
                  // initialize the object as you want. the model class is shown below
     
                   result.Result = response;
                }
    the model

     
    public class DatabaseServerTypesResponse
        {
            /// <summary>
            /// 
            /// </summary>
            [DataMember]
            [JsonProperty]
            public List<DatabaseServerCredentialType> DatabaseServerCredentialTypes { get; set; }
            /// <summary>
            /// 
            /// </summary>
            ///  
            [JsonProperty]
            public List<DatabaseServerType> DatabaseServerTypes { get; set; }
            /// <summary>
            /// 
            /// </summary>
            [JsonProperty]
            public DatabaseConfigurationSettings DatabaseConfigurationSettings { get; set; }
        }
     
     
    public class DatabaseServerCredentialType
        {
            /// <summary>
            /// 
            /// </summary>
            [DataMember]
            [JsonProperty]
            public DatabaseCredentialType DatabaseCredentialType { get; set; }
            /// <summary>
            /// 
            /// </summary>
            [DataMember]
            [JsonProperty]
            public String DisplayName { get; set; }
        }
     
    public class DatabaseServerType
        {
            /// <summary>
            /// 
            /// </summary>
            [DataMember]
            [JsonProperty]
            public DatabaseTypes DatabaseType { get; set; }
            /// <summary>
            /// 
            /// </summary>
            [DataMember]
            [JsonProperty]
            public String DisplayName { get; set; }
        }
     
     
    public class JavaScriptAjaxResult
        {
            public JavaScriptAjaxResult()
            {
                Error = "";
                Exception = "";
            }
            // the error property. this value is set only when there is an error. 
            // this parameter is used to check if the execution is successful or not
            [JsonPropertyAttribute("error")]
            public string Error { get; set; }
            // hold the value of the exceprion thrown during the action execution
            [JsonPropertyAttribute("exception")]
            public string Exception { get; set; }
            // hold the result if any.
            [JsonPropertyAttribute("result")]
            public object Result { get; set; }
     
            // returns the JSON string representation of the class. This method must be called by the controller action that 
            public string ToJson()
            {
                return JsonConvert.SerializeObject(this, Formatting.Indented);
            }
        }
    Last edited by Daniil; May 05, 2011 at 3:08 PM. Reason: [CLOSED]
  2. #2
    Hi,

    The following code doesn't make sense when the store is already rendered.
    DatabaseTypesStore.data = resultData.result.DatabaseServerTypes;
    Please try .loadData() method.
    DatabaseTypesStore.loadData(resultData.result.DatabaseServerTypes);
    Please see the docs what object .loadData() expects.
    http://dev.sencha.com/deploy/ext-3.3...ember=loadData
  3. #3
    Thanks. it worked . But I had to use
    DatabaseTypesStore.loadData({data:resultData.result.DatabaseServerTypes});
    because this was throwing exceptions
    DatabaseTypesStore.loadData(resultData.result.DatabaseServerTypes);
    Last edited by Daniil; May 05, 2011 at 3:05 PM. Reason: Please use [CODE] tags
  4. #4
    Sure, I just gave the direction, not investigated how looks a response.

Similar Threads

  1. [CLOSED] Assigning and adding data in Text Field
    By Digital.Dynamics in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 24, 2012, 9:33 AM
  2. Replies: 4
    Last Post: Jan 12, 2012, 12:47 PM
  3. Replies: 5
    Last Post: May 17, 2011, 10:10 AM
  4. [CLOSED] Loading data from server to store by javascript
    By leon_tang in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 21, 2011, 5:44 PM
  5. Replies: 11
    Last Post: Dec 14, 2010, 7:42 AM

Posting Permissions