Mar 02, 2015, 11:39 PM
[CLOSED] store.LoadData not working - Uncaught SyntaxError: Unexpected token ILLEGAL
I have a Form and a Grid Defined in a window as below -
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 -
Can you please help.
@(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]