convertsTo
Static method to create an extended ObservableArray
where each item is a specific type.
ObservableArray.convertsTo(Type)
Returns an ObservableArray
constructor with its static items property set to the Type
argument. This can be used to define the Typed properties.
<my-app></my-app>
<script type="module">
import { ObservableArray, ObservableObject, StacheElement, type } from "can/everything";
class Person extends ObservableObject {
static props = {
name: String
}
}
class MyApp extends StacheElement {
static props = {
people: type.convert( ObservableArray.convertsTo(Person) )
};
static view = `
{{# for(person of people) }}
Welcome {{ person.name }}
{{/ for }}
`;
}
customElements.define('my-app', MyApp);
const app = document.querySelector('my-app');
app.people = [{ name: 'Matt' }];
</script>
Parameters
- Type
{Object|function}
:The underlying type that will be set on items.
Returns
An extended ObservableArray with the items converting to the provided type.