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

Workaround for objects with IDs as arrays?

1 Answer 108 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 08 Feb 2016, 10:22 PM

I am working a set of data that contains arrays as IDs. I need some help working around this as it appears unsupported and breaks some things.

Example item from the first set of data:

{
  "id":[1,2,3,4],
  "name":"Another VIP-VID-INPUT-1",
  "internal":true
}

This data is referenced from second set of data which uses the same array IDs to refer to the first set. Example item from the second set of data:

{
  "id":2,
  "name":"Link 02",
  "head_port_id":[1,2,3,4],
  "tail_port_id":[2,2,3,4],
  "disabled":false
}

For starters I am populating a Grid with the second set of data. I use a column.template to replace "head_port_id" and "tail_port_id" with the relevant "name" field from the first set of data. This works fine.

The problem arises when I try to use a DropDownMenu inside column.editor for the "head_port_id" and "tail_port_id" columns. Clicking the cell causes an error. 

editor: function(container, options) {
    var editor = $('<input />')
        .attr('name', options.field) // "head_port_id"
        .attr('required', 'required')
        .attr('data-bind', 'value:' + options.field); // "head_port_id"
     
    container.append(editor);
     
    editor.kendoDropDownList({
        autoBind: false,
        dataSource: data.ports.datasource, // the first set of data
        dataTextField: 'name',
        dataValueField: 'id'
    });
}
  The error I get looks like this:

Uncaught TypeError: o[s].get is not a function
E.widget.value.v.extend.refresh @ kendo.all.js:8886
I.extend.bind @ kendo.all.js:8153
w.extend.applyBinding @ kendo.all.js:9146
I.extend.bind @ kendo.all.js:9096
a @ kendo.all.js:9239
a @ kendo.all.js:9247
a @ kendo.all.js:9247
s @ kendo.all.js:9262
c.extend.refresh @ kendo.all.js:36822
c.extend.init @ kendo.all.js:36731
(anonymous function) @ kendo.all.js:2382
b.extend.each @ jquery-1.9.1.min.js:3
b.fn.b.each @ jquery-1.9.1.min.js:3
e.fn.(anonymous function) @ kendo.all.js:2381
ue.ui.DataBoundWidget.extend.editCell @ kendo.all.js:45210
(anonymous function) @ kendo.all.js:45168
b.event.dispatch @ jquery-1.9.1.min.js:3
v.handle @ jquery-1.9.1.min.js:3

Since I have the minified code it's difficult to debug this, even though I can see the full source code (a source map is loaded I assume). Breakpoints and scope vars aren't cooperating.

Anyway I had an idea which was to define a "parse" function for all of the array ID fields, in my Models. It simply converted the ID arrays .toString(). This works pretty well except that it has a fatal flaw in which the data I send to the relevant service is now invalid, since the service is expecting arrays and not strings.

How can I convert these IDs back to arrays, ideally without doing this in the DataSource transport functions (update, create, etc)? I have a generic DataSource wrapper that I am using to wrap our own CRUD interface.. I don't want it to have special cases in it for this once type of data.

1 Answer, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 11 Feb 2016, 05:09 PM
Hi,

Sorry for the delay.

I'm pretty certain that we don't support arrays for ID values. These values should be comparable with simple equality operators and arrays do not satisfy that.
I can't see that clearly stated in the Model documentation and will make sure to add it there.

Apologies for the caused inconvenience.

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Ryan
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Share this question
or