JSFiddle - React, Tailwind, and code Playground
http://forums.enyojs.com/discussion/2129/how-would-you-go-about-binding-simple-json-to-a-data-repeater
by Ryan Duffy
JavaScript
enyo.kind({
name: "MyModel",
kind: enyo.Model,
noDefer: true,
constructor: enyo.inherit(function(sup) {
return function(attr, props, opts) {
opts = enyo.mixin(opts, {parse: true});
if(enyo.isString(attr)) {
sup.call(this, {id: attr}, props, opts);
} else {
sup.apply(this, arguments);
}
};
}),
parse: function(obj) {
if(obj.hasOwnProperty("id")) {
return {
value: obj.id
};
} else {
return obj;
}
}
});
enyo.kind({
name: "ex.App",
bindings: [
{from: ".data", to: ".$.list.collection"}
],
components: [
{name: "list", kind: "DataRepeater", components: [
{kind: "onyx.Item", components: [
{name: "content"}
], bindings: [
{from: ".model.value", to: ".$.content.content"}
]}
]}
],
create: enyo.inherit(function(sup) {
return function() {
sup.apply(this, arguments);
this.set("data", new enyo.Collection({
model: MyModel
}));
this.data.add([
"First",
"Second",
"Third"
]);
// this doesn't work in nightly on 2014/05/28
// seems like a bug in enyo.Collection.add
// this.data.add(new MyModel("Fourth"));
};
})
});
new ex.App().renderInto(document.body);