[CLOSED] store.LoadData not working - Uncaught SyntaxError: Unexpected token ILLEGAL

  1. #1

    [CLOSED] store.LoadData not working - Uncaught SyntaxError: Unexpected token ILLEGAL

    I have a Form and a Grid Defined in a window as below -

    @(X.Window()
    		.ID("wineditor")
    		.Icon(Icon.Cog)
    		.Hidden(true)
    		.Width(700)
    		.Height(500)
    		.Layout(LayoutType.Border)
    		.Resizable(false)
    		.Closable(false)
    		.Border(false)
    		.Items(
    			Html.X().FormPanel()
    				.Region(Region.North)
    				.ID("FormPanelRequest")
    				.Frame(true)
    				.DefaultAnchor("100%")
    				.Layout(LayoutType.Column)
    				.BodyPadding(6)
    				.FieldDefaults(def =>
    				{
    					def.MsgTarget = MessageTarget.Side;
    				})
    				.Items(
    					X.Panel()
    						.ColumnWidth(0.50)
    						.Items(
    							X.TextFieldFor(m => m.RequestNumber).ID("txtRequestNumber").Name("RequestNumber"),
    							X.TextFieldFor(m => m.RequestedBy).ID("txtRequestedBy").Name("RequestedBy"),
    							X.ComboBoxFor(m => m.MealType).ID("drpMealType").Name("MealType")
    								.Items(
    									"Breakfast", "Lunch", "Dinner"
    								),
    							X.TextFieldFor(m => m.Status).ID("txtStatus").Name("Status")
    						),
    					X.Panel()
    						.ColumnWidth(0.50)
    						.Items(
    							X.DateFieldFor(m => m.RequestDate).ID("txtRequestDate").Name("RequestDate"),
    							X.DateFieldFor(m => m.RequiredOn).ID("txtRequiredOn").Name("RequiredOn"),
    							X.NumberFieldFor(m => m.NumberOfPeople).ID("txtNumberOfPeople").Name("NumberOfPeople")
    						)
    				),
    			X.GridPanel()
    					.Region(Region.Center)
    					.ColumnWidth(0.6)
    					.ID("gridItems")
    					.Layout(LayoutType.Fit)
    					.Store(X.Store().ID("storeItems")
    						.AutoLoad(true)
    						.Model(X.Model().IDProperty("Id")
    							.Fields(f => {
    								f.Add(X.ModelField().Name("Id"));
    								f.Add(X.ModelField().Name("Name"));
    								f.Add(X.ModelField().Name("Description"));
    							})
    						)
    					)
    					.ColumnModel(
    						X.Column().Text("Name").DataIndex("Name").Width(200),
    						X.Column().Text("Description").DataIndex("Description").Flex(1)
    					)
    					.View(Html.X().GridView().StripeRows(true).TrackOver(true)),
    		)
    )
    I am populating the Data in Form and grid through a direct method from JavaScript as

    var handleRowCommand = function (command, recordId) {
    	if (command == 'View') {
    		App.direct.showRequestData(recordId, App.gridItems.getStore().getId(), {
    			success: function (result) {
    				App.wineditor.show();
    			}
    		});
    	}
    }
    The showRequestData method in action class is defined as below -

    [DirectMethod]
    public ActionResult showRequestData(int requestId, String itemStoreId)
    {
    	this.GetCmp<TextField>("txtRequestNumber").SetValue(100);
    	this.GetCmp<TextField>("txtRequestedBy").SetValue(1);
    	this.GetCmp<ComboBox>("drpMealType").SetValue("Breakfast");
    	this.GetCmp<TextField>("txtStatus").SetValue("Closed");
    	this.GetCmp<DateField>("txtRequestDate").SetValue(DateTime.Now);
    	this.GetCmp<DateField>("txtRequiredOn").SetValue(DateTime.Now);
    	this.GetCmp<NumberField>("txtNumberOfPeople").SetValue(10);
    
    	List<CafeteriaItem> Items = new List<CafetariaItem>();
    	Items.Add(new CafeteriaItem { Id = 1, Name = "Item A", Description = "Item A Desc", IsActive = true });
    	Items.Add(new CafeteriaItem { Id = 2, Name = "Item B", Description = "Item B Desc", IsActive = true });
    	Items.Add(new CafeteriaItem { Id = 3, Name = "Item C", Description = "Item C Desc", IsActive = true });
    
    	this.GetCmp<Store>(itemStoreId).LoadData(Items);
    
    	return this.Direct();
    }
    CafeteriaItem is defined as follows -

    public class CafeteriaItem
    {
    	public Int32 RequestNumber { get; set; }
    	public Int32 Id { get; set; }
    	public String Name { get; set; }
    	public String Description { get; set; }
    	public bool IsActive { get; set; }
    }
    If I can see data being populated in the fields if I comment this line - this.GetCmp<Store>(itemStoreId).LoadData(Items);

    But the problem is populating the store "storeItems". LoadData() in not populating the grid, instead getting a JavaScript error - "Uncaught SyntaxError: Unexpected token ILLEGAL".

    When I further inspect in Chrome console, I found showRequestData() action method is returning following -

    App.txtRequestNumber.setValue(100);
    App.txtRequestedBy.setValue(1);
    App.drpMealType.setValue("Breakfast");
    App.txtStatus.setValue("Closed");
    App.txtRequestDate.setValue(new Date(2015,2,3,5,47,29,68));
    App.txtRequiredOn.setValue(new Date(2015,2,3,5,47,29,71));
    App.txtNumberOfPeople.setValue(10);
    App.ext-data-store-3.loadData([{"RequestNumber":0,"Id":1,"Name":"Item A","Description":"Item A Desc","IsActive":true},{"RequestNumber":0,"Id":2,"Name":"Item B","Description":"Item B Desc","IsActive":true},{"RequestNumber":0,"Id":3,"Name":"Item C","Description":"Item C Desc","IsActive":true}]);
    this line in action method is causing the issue - "this.GetCmp<Store>(itemStoreId).LoadData(Item s);"

    Can you please help.
    Last edited by fabricio.murta; Mar 03, 2015 at 4:50 AM. Reason: [CLOSED]
  2. #2
    Ok. I realized "App.ext-data-store-3" is the culprit. Not sure why App.gridItems.getStore().getId() returned such ID.

    Anyway my solution is -

    replace

    this.GetCmp<Store>(itemStoreId).LoadData(Items);
    with

    this.GetCmp<Store>("storeItems").LoadData(Items);
    Please mark it as closed.
  3. #3
    Thanks, @barnali, for not only sharing the problem, but the solution! This is very welcome, as others might make the same mistake in the future and google for it. :)
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Error BADRESPONSE: Unexpected token ILLEGAL
    By aydada in forum 2.x Help
    Replies: 2
    Last Post: Aug 07, 2014, 10:46 AM
  2. Replies: 4
    Last Post: Jun 16, 2014, 5:44 AM
  3. Unexpected token: ,
    By MartineNavara in forum 2.x Help
    Replies: 3
    Last Post: Oct 18, 2013, 4:23 AM
  4. Replies: 3
    Last Post: Oct 10, 2013, 4:03 PM
  5. Replies: 3
    Last Post: Jan 03, 2011, 5:28 PM

Posting Permissions