Skip to content

Instantly share code, notes, and snippets.

@taosx
Created May 27, 2015 09:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save taosx/58fbd4ea59070dd9405b to your computer and use it in GitHub Desktop.
Save taosx/58fbd4ea59070dd9405b to your computer and use it in GitHub Desktop.
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