Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extract information from a json file using mithril m.request()
// MODEL
'use strict';
var m = require('mithril');
var config = module.exports = {};
config.himage = m.request({
method: 'GET',
url: '/config.json'
})
.then(JSON.parse)
.then(function (data) {
return data["himage"];
});
module.exports = config;
// COMPONENT
'use strict';
var m = require('mithril');
var config = require('../models/config');
var Slider = module.exports = {
controller: function () {
var ctrl = this;
},
view: function (ctrl) {
return m("img[alt='slider image 1'][src='" + config.himage() + "']")
};
// JSON DATA
[
"{\n\t\"title\": \"Site title name\",\n\t\"description\": \"Site description\",\n\t\"keywords\": \"Site, keywords\",\n\t\"aboutus\": \"Site about us\",\n\t\"contact\": {\n\t\t\"phones\": {\n\t\t\t\"fix1\": \"0210545665\",\n\t\t\t\"fix2\": \"0210545665\",\n\t\t\t\"mobile1\": \"0732577794\",\n\t\t\t\"mobile2\": \"0732577794\",\n\t\t\t\"mobile3\": \"0732577794\",\n\t\t\t\"fax1\": \"0210545665\",\n\t\t\t\"fax2\": \"0210545665\"\n\t\t},\n\t\t\"adresses\": {\n\t\t\t\"adress1\": \"Placeholder, A1\",\n\t\t\t\"adress2\": \"Placeholder, A2\"\n\t\t},\n\t\t\"email\": {\n\t\t\t\"email1\": \"adress@email.com\",\n\t\t\t\"email2\": \"adress@email.com\"\n\t\t}\n\t},\n\t\"himage\": \"style/images/slider/slide1.jpg\"\n}"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.