Alloy lazy transformation pattern #13574
Answered
by
m1ga
beppo-ivel
asked this question in
Q&A
-
Under section Alloy Data-Binding there is explained how to transform model attributes for data binding. Is it possible to call model.js
controller.js
|
Beta Was this translation helpful? Give feedback.
Answered by
m1ga
Sep 17, 2022
Replies: 1 comment 1 reply
-
only tested it with my model that doesn't have dates so I've used a simple string: transform: function() {
var model = this;
var t = this.toJSON();
Object.defineProperty(t, 'dateFormatted', {
get: function() {
return "test";
}
});
return t;
} var book = Alloy.createModel('library', {
title: 'Title' + Math.floor(Math.random() * 1000),
subtitle: 'asdfasdf ' + Math.floor(Math.random() * 1000),
image: 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/SIPI_Jelly_Beans_4.1.07.tiff/lossy-page1-220px-SIPI_Jelly_Beans_4.1.07.tiff.jpg'
});
console.log(book.transform());
console.log(book.transform().dateFormatted); and it will log
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
beppo-ivel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
only tested it with my model that doesn't have dates so I've used a simple string:
and it will log