Javascript Array: Change elements from string to object

I am using the ParamQuery JavaScript library (ParamQuery Website) to build a JavaScript grid.

With JQuery I make a request to my service using Ajax which retunrs JSON data. I then loop through my JSON data and assign it to an array. My problem is the elements are strings but I think they need to be an array of objects.

<script type="text/javascript">
    $(document).ready(function () {
        var DataArray = [];

        $.ajax({
            url: "http://wks52025:82/WcfDataService.svc/GetNotes()?$format=json",
            type: "get",
            datatype: "json",
            success: function (data) {
                $.each(data.d, function (i, item) {
                    DataArray[i] = "[" + item.NotesTitle.trim() + "," + item.NotesText.trim() + "]";
                })

                for (var i = 0; i < DataArray.length; i++) {
                    //alert(DataArray[i]);
                    //Do something
                }

                // GRID LOGIC HERE
                var obj = { width: 800, height: 400, title: "Notes" };
                obj.colModel = [
                    { title: "NotesTitle", width: 500, dataType: "string" },
                    { title: "NotesText", width: 500, dataType: "string" } 
                ];
                obj.dataModel = { data: DataArray }; // Data Array goes here
                $("#grid_array").pqGrid(obj);
            }
        });    
    });
</script>

I have attached screenshots of my Watch tab in VS and a screenshot of how the grid renders after debug.

This is the example code

Can anyone help me solve this problem?

Answers


If the question is only about turning this to array of objects take a look at this line:

$.each(data.d, function (i, item) {
  DataArray[i] = { NotesTitle: item.NotesTitle.trim(), NotesText:item.NotesText.trim() };
})

Update Had a look a the example, you need an Array of arrays

$.each(data.d, function (i, item) {
  DataArray[i] = [  item.NotesTitle.trim(), item.NotesText.trim() ];
})

Need Your Help

how to know $HOME in a .deb package

linux package dpkg

I am making a debian package that includes some libraries.

Can Visual Studio nuget package manager exclude pre-release packages?

visual-studio-2010 entity-framework nuget t4scaffolding

I'm using a package for generating email from Razor views caller MvcMailer. This package depends on T4Scaffolding (>= 1.0.7). T4Scaffolding in turn depends on EntityFramework (>= 4.1.10311.0).