Last active
September 5, 2015 08:23
-
-
Save LightSpeedC/774d23baaf9ca24a130f to your computer and use it in GitHub Desktop.
Mithril.js 試してみた(2) サーバーからデータを取得する m.request() ref: http://qiita.com/LightSpeedC/items/f533f048e01ac19a06ec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="UTF-8"> | |
<title>links - Mithril.js</title> | |
<script src="mithril.min.js"></script> | |
<!--[if IE]><script src="es5-shim.min.js"></script><![endif]--> | |
<body> | |
<div id="$linksElement"></div> | |
</body> | |
<script> | |
// コンポーネント定義 | |
var linksComponent = { | |
// コントローラ | |
controller: function () { | |
// データをサーバーから取得する | |
this.list = m.request({method: 'GET', url: 'links.json', initialValue: []}); | |
}, | |
// ビュー | |
view: function (ctrl) { | |
return m('ul', | |
ctrl.list().map(function (item) { | |
return m('li', [m('a', {href: item.url}, item.title)]); | |
}) | |
); | |
} | |
}; | |
m.mount($linksElement, linksComponent); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{"title": "qiita.com", "url": "http://qiita.com"}, | |
{"title": "google", "url": "http://www.google.co.jp"}, | |
{"title": "facebook", "url": "http://www.facebook.com"} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment