0
votes

Has anyone built metadata by hand for an array type? For example, I just want to bind a

List selectedIds;

to my metadata on the client side. I then want to bind this to an array that corresponds to some checkbox values. Oddly, when I create my new entity the value I am sending for my property is not bound and sent to the server.

var registrationFormModel = ko.observable(); registrationFormModel({ selectedIds: ko.observableArray(), name: ko.observable() });

Later on I set a name and the selectedIds to an array of ints. But it does not map to my entity. Is there a way to have an array type property?

2

2 Answers

1
votes

You certainly can define a data property which is an array of simple values (e.g., an array of integers). You can also define a property which is an array of "complex types" (as Breeze understands the word).

These are array data properties. They are not collection navigation properties. If you want to use them to acquire and present their implied related entities, you'll have to manage that yourself.

You didn't tell us how you are storing the data on the server. It appears that you are not using a relational database because an RDB doesn't support array properties. A document database (e.g, MongoDb) DOES.

That's OK from a Breeze perspective. But it is important for us to ask and understand what you're doing if we are to provide appropriate help.

Your question reminds me that our documentation doesn't cover array data properties. The "zza-node-mongo" sample does illustrate array properties in metadata created by hand.

Here is an example from that metadata definition of an array of integer FK ids which is what you seek, right?

Here is an example of an array of complex types that is not a navigation property.

This metadata sample relies on the "metadata-helper" in Breeze Labs. That's why you see hasMany: true which is an alias for the actual Breeze metadata equivalent, isScalar: false.

-1
votes

Currently I don't think you can create a property that is an array of simple objects.

There are two methods you could use though -

  1. Pass your collection of Id's down from the server as a complex type with a name/value object -

    [{id: 1}, {id: 2}]

  2. Use a JsonResultsAdapter to map your simple array to a complex type similar to mentioned above -

    if (node.IntArray) { var tempArray = []; $.each(node.IntArray, function (index, item) { tempArray.push({id: item}); } node.IntArray = tempArray; }