This is a migrated thread and some comments may be shown as answers.

Mapping dataSource.schema.model.id causes 'undefined' error.

2 Answers 531 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Richard H
Top achievements
Rank 1
Richard H asked on 02 Mar 2012, 08:11 PM
Hi there,

I am trying to map a field defined in my datasource schema to the unique Model instance id property. However, after I do this the field in the model no longer displays correctly when the datasource is bound to a list. The value for "PONumber" field is always 'Undefined' after this mapping is defined. If I comment out the line which maps the "PONumber" field to id, the expected value from the "PONumber" field shows up in the output. However, because there is no id mapping which uniquely identifies the Model instance calls like get(id) won't work.

[Edit: I am using 2012.1.229.beta]

Here is the code I'm using (see attachment for code and sample data file): 
<!DOCTYPE html>
<html>
<head>
    <title>Repro</title>   
    <script src="js/jquery.min.js"></script>
    <script src="source/js/kendo.all.js"></script>
    <link href="source/styles/kendo.common.css" rel="stylesheet" />   
    <link href="source/styles/kendo.mobile.all.css" rel="stylesheet" />
</head>
<body>
    <div data-role="view" id="tabstrip-listview" data-init="initList" data-title="PO List" data-layout="tabstrip-layout">
        <ul id="po-listview"/>
    </div>
    <script>
        var app = new kendo.mobile.Application(document.body);
        var ds = new kendo.data.DataSource({
            transport: {
                read: "Data/POListTest.xml"
            },
            schema: {
                type: "xml",
                data: "/ItemInfoList/ItemInfo",               
                model: {
                    id: 'PONumber', // *** Commenting out this line fixes the problem ***
                    fields: { PONumber: "Item/PurchaseOrderHeader/POHdrPONumber/text()" }
                }
            }
        });
 
        function initList() {
            $("#po-listview").kendoMobileListView({ dataSource: ds, template: "${PONumber}" });
        };
 
    </script>
</body>
</html>

Any ideas what is happening here?

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 05 Mar 2012, 09:40 AM
Hi Richard,

The behavior you have described is caused by incorrect id field setup. The id in this case should the an expression which points to a field from the original data, not  from the processed one:

schema: {
      type: "xml",
      data: "/ItemInfoList/ItemInfo",              
      model: {
          id: "Item/PurchaseOrderHeader/POHdrPONumber/text()",
          fields: { PONumber: "Item/PurchaseOrderHeader/POHdrPONumber/text()" }
      }
  }

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Richard H
Top achievements
Rank 1
answered on 05 Mar 2012, 05:31 PM
Thanks, that worked! The documentation is a bit confusing and made it seem like it should be the field name from the "fields" collection.
Tags
Data Source
Asked by
Richard H
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Richard H
Top achievements
Rank 1
Share this question
or