{"id":1010,"date":"2019-06-15T23:05:56","date_gmt":"2019-06-15T14:05:56","guid":{"rendered":"https:\/\/ito-u-oti.com\/?p=1010"},"modified":"2019-06-15T23:05:59","modified_gmt":"2019-06-15T14:05:59","slug":"post-1010","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=1010","title":{"rendered":"\u3010RequireJS\u3011\u3010BackboneJS\u3011\u3010HighchartsJS\u3011backboneJS\u3067highchartsJS\u3092\u4f7f\u3046\u2010\u305d\u306e\uff12"},"content":{"rendered":"\n<p>\u524d\u56de\u8a18\u4e8b\u306e\u7d9a\u304d\u3067\u3059\u3002<br><a href=\"https:\/\/ito-u-oti.com\/post-979\/\">\u3010RequireJS\u3011\u3010BackboneJS\u3011\u3010HighchartsJS\u3011backboneJS\u3067highchartsJS\u3092\u4f7f\u3046\u2010\u305d\u306e\uff11<\/a><\/p>\n\n\n\n<p>\u524d\u56de\u306fhighcharts\u306b\u56fa\u5b9a\u5024\u3092\u8a2d\u5b9a\u3057\u3066View\u3067\u305d\u306e\u307e\u307e\u753b\u9762\u306b\u8868\u793a\u3055\u305b\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306fbackbone\u306eCollection\u3092\u4f7f\u3063\u3066\u30b5\u30fc\u30d0\u304b\u3089\u53d6\u5f97\u3057\u305f\u60c5\u5831\u3092highcharts\u306e\u30c7\u30fc\u30bf\u3068\u3057\u3066\u4f7f\u7528\u3057\u3066\u753b\u9762\u306b\u8868\u793a\u3055\u305b\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__1\" class=\"wp-block-heading\">\u524d\u63d0<\/h2>\n\n\n\n<h3 id=\"outline__1_1\" class=\"wp-block-heading\">\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u6210<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"283\" height=\"363\" src=\"https:\/\/ito-u-oti.com\/wp-content\/uploads\/2019\/06\/019_backboneJS1.png\" alt=\"\" class=\"wp-image-1012\"\/><\/figure>\n\n\n\n<h3 id=\"outline__1_2\" class=\"wp-block-heading\"> \u30b5\u30fc\u30d0\u5074\u60c5\u5831 (Hello)<\/h3>\n\n\n\n<h4 id=\"outline__1_2_1\" class=\"wp-block-heading\"> REST URL<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ncurl -X GET http:\/\/localhost:3000\/hello\n<\/pre><\/div>\n\n\n<h4 id=\"outline__1_2_2\" class=\"wp-block-heading\"> \u53d6\u5f97\u30c7\u30fc\u30bf <\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n  &quot;hello&quot;: {\n    &quot;text&quot;: &quot;Hello World Backbone Fetch!!&quot;\n  }\n}\n<\/pre><\/div>\n\n\n<h3 id=\"outline__1_3\" class=\"wp-block-heading\"> \u30b5\u30fc\u30d0\u5074\u60c5\u5831 (HelloValue) <\/h3>\n\n\n\n<h4 id=\"outline__1_2_1\" class=\"wp-block-heading\"> REST URL<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ncurl -X GET http:\/\/localhost:3000\/helloValue\n<\/pre><\/div>\n\n\n<h4 id=\"outline__1_3_2\" class=\"wp-block-heading\"> \u53d6\u5f97\u30c7\u30fc\u30bf  <\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{\n  &quot;helloValue&quot;: &#x5B;\n      {\n          &quot;num&quot;:0.5\n      },\n      {\n          &quot;num&quot;:1.5\n      }\n  ]\n}\n\n<\/pre><\/div>\n\n\n<h2 id=\"outline__2\" class=\"wp-block-heading\">requireJS+backboneJS+highchartsJS <\/h2>\n\n\n\n<h3 id=\"outline__2_1\" class=\"wp-block-heading\">index.html<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;ja&quot;&gt;\n    &lt;head&gt;\n        &lt;meta charset=&quot;utf-8&quot;&gt;\n        &lt;title&gt;&lt;\/title&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;script src=&quot;https:\/\/requirejs.org\/docs\/release\/2.3.6\/minified\/require.js&quot;&gt;&lt;\/script&gt;\n        &lt;script src=&quot;.\/js\/config\/config.js&quot;&gt;&lt;\/script&gt;\n        &lt;script src=&quot;.\/js\/views\/HelloWorldView.js&quot;&gt;&lt;\/script&gt;\n        &lt;script type=&quot;text\/template&quot; id=&quot;hello-template&quot;&gt;\n            &lt;h2&gt;&lt;%= text %&gt;&lt;\/h2&gt;\n        &lt;\/script&gt;\n        &lt;h1&gt;Hello World!&lt;\/h1&gt;\n        &lt;div class=&quot;hoge&quot;&gt;&lt;\/div&gt;\n        &lt;div id=&quot;container&quot;&gt;&lt;\/div&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n<p> hoge\u30af\u30e9\u30b9\u3068containerID\u304c\u4ed8\u4e0e\u3055\u308c\u3066\u3044\u308bdev\u30bf\u30b0\u3092\u305d\u308c\u305e\u308c\u4f5c\u6210\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br>hoge\u306bModel\u306e\u5185\u5bb9\u304c\u5165\u308a\u307e\u3059\u3002<br>container\u306b\u30b0\u30e9\u30d5\u304c\u63cf\u753b\u3055\u308c\u307e\u3059\u3002 <\/p>\n\n\n\n<h3 id=\"outline__2_2\" class=\"wp-block-heading\">config.js<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nrequire.config({\n    packages: &#x5B;{\n        name: 'highcharts',\n        main: 'highcharts'\n    }],\n    baseUrl: &quot;js&quot;,\n    paths: {\n        &quot;backbone&quot; : &quot;lib\/backbone&quot;,\n        &quot;jquery&quot; : &quot;lib\/jquery&quot;,\n        &quot;underscore&quot; : &quot;lib\/underscore&quot;,\n        \/\/'highcharts': 'https:\/\/code.highcharts.com'\n        &quot;highcharts&quot;: &quot;lib&quot;\n    },\n    shim: {\n        'backbone' : {\n            deps: &#x5B;'underscore', 'jquery'],\n            exports: 'Backbone'\n        }\n    }\n});\n\n<\/pre><\/div>\n\n\n<p> backboneJS\u3068highchartsJS\u306e\u8aad\u307f\u8fbc\u307f\u8a2d\u5b9a\u3092\u884c\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br>highcharts\u306epaths\u8a2d\u5b9a\u3067URL\u306e\u65b9\u304c\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e0a\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u7528\u3057\u305f\u3044\u5834\u5408\u306fURL\u6307\u5b9a\u3067\u3082\u884c\u3051\u308b\u3088\u3068\u3044\u3046\u610f\u5473\u3067\u4e00\u5fdc\u8a18\u8f09\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h3 id=\"outline__2_3\" class=\"wp-block-heading\"> HelloWorldModel.js <\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\ndefine(&#x5B;'backbone'], function(backbone) {\n\n    var HelloWorldModel = backbone.Model.extend({\n        url: &quot;http:\/\/localhost:3000\/hello&quot;,\n        defaults: {\n            &quot;text&quot;:&quot;Hello World Backbone!!&quot;\n        },\n        read: function(){\n            this.fetch()\n        }\n    });\n    return HelloWorldModel;\n});\n<\/pre><\/div>\n\n\n<p>fetch\u304c\u6210\u529f\u3059\u308b\u3068\u3001text\u304c\u300cHello World Backbone fetch!!\u300d\u306b\u4e0a\u66f8\u304d\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 id=\"outline__2_4\" class=\"wp-block-heading\">HelloWorldCollection.js<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\ndefine(&#x5B;'backbone'], function(backbone) {\n\n    var HelloWorldCollection = backbone.Collection.extend({\n        url: &quot;http:\/\/localhost:3000\/helloValue&quot;,\n        defaults: {\n            &quot;text&quot;:&quot;Hello World Backbone!!&quot;\n        },\n        read: function(){\n            this.fetch()\n        }\n    });\n    return HelloWorldCollection;\n});\n<\/pre><\/div>\n\n\n<p>helloValue\u306efetch\u3067\u53d6\u5f97\u3059\u308b\u30c7\u30fc\u30bf\u304c\u914d\u5217\u3068\u306a\u308b\u306e\u3067\u3001backbone\u306eCollection\u3092\u4f7f\u3044\u307e\u3059\u3002<br>Collection\u306e\u5404\u8981\u7d20\u306bnum\u3068\u3044\u3046\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u751f\u6210\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 id=\"outline__2_5\" class=\"wp-block-heading\">HelloWorldView.js<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\nrequire(&#x5B;'backbone', 'model\/HelloWorldModel', 'collection\/HelloWorldCollection', 'highcharts'],\nfunction(backbone, helloWorldModel, helloWorldCollection, hi) {\n\n    var model = new helloWorldModel();\n    var collection = new helloWorldCollection();\n\n    var HelloWorldView = backbone.View.extend({\n        el: $('.hoge'),\n        initialize: function() {\n            model.read();\n            this.listenToOnce( model, 'sync', this.render);\n            collection.read();\n            this.listenToOnce( collection, 'sync', this.graph);\n        },\n        render: function() {\n            $(this.el).html(_.template($('#hello-template').text())({ &quot;text&quot;: model.get(&quot;text&quot;) }));\n        },\n        graph: function() {\n            hi.chart('container', {\n                chart: {\n                    renderTo: 'chart',\n                    type: 'bar'\n                },\n                title: {\n                    text: 'Hello Highcharts'\n                },\n                xAxis: {\n                    categories: &#x5B;'Hello', 'World']\n                },\n                yAxis: {\n                    title: 'Value'\n                },\n                series: &#x5B;{\n                    name: 'Highcharts Intro',\n          \t         data: &#x5B;collection.at(0).get('num'), collection.at(1).get('num')]\n                }]\n            });\n        }\n    });\n    new HelloWorldView();\n});\n\n<\/pre><\/div>\n\n\n<ol class=\"wp-block-list\"><li>model\u306eread\u3092\u547c\u3073\u51fa\u3057\u3001\u30b5\u30fc\u30d0\u304b\u3089\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b<\/li><li> listenToOnce\u3067model\u306e\u72b6\u614b\u3092\u76e3\u8996\u3057\u3001model\u304c\u5909\u5316\u3057\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u3067View\u306erender\u3092\u547c\u3073\u51fa\u3059<\/li><li>read\u3057\u305f\u6642\u70b9\u3067model\u306etext\u304c\u4e0a\u66f8\u304d\u3055\u308c\u3001model\u306e\u72b6\u614b\u304c\u5909\u308f\u3063\u305f\u305f\u3081render\u304c\u547c\u3073\u51fa\u3055\u308c\u3001template\u304c\u753b\u9762\u306b\u633f\u5165\u3055\u308c\u308b<\/li><li>collection\u306eread\u3092\u547c\u3073\u51fa\u3057\u3001\u30b5\u30fc\u30d0\u304b\u3089\u914d\u5217\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b<\/li><li>listenToOnce\u3067collection\u306e\u72b6\u614b\u3092\u76e3\u8996\u3057\u3001collection\u304c\u5909\u5316\u3057\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u3067View\u306egraph\u3092\u547c\u3073\u51fa\u3059<\/li><li>read\u3057\u305f\u6642\u70b9\u3067collection\u306bnum\u304c\u751f\u6210\u3055\u308c\u3001collection\u306e\u72b6\u614b\u304c\u5909\u308f\u3063\u305f\u305f\u3081graph\u304c\u547c\u3073\u51fa\u3055\u308c\u3001highcharts\u306e\u30b0\u30e9\u30d5\u304c\u753b\u9762\u306b\u63cf\u753b\u3055\u308c\u308b <\/li><\/ol>\n\n\n\n<h3 id=\"outline__2_6\" class=\"wp-block-heading\">\u8868\u793a<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"820\" height=\"574\" src=\"https:\/\/ito-u-oti.com\/wp-content\/uploads\/2019\/06\/019_1_backboneJS1.png\" alt=\"\" class=\"wp-image-1014\"\/><\/figure>\n\n\n\n<p>\u68d2\u30b0\u30e9\u30d5\u306e\u6570\u5024\u304c\u30b5\u30fc\u30d0\u304b\u3089\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__3\" class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u4eca\u307e\u3067\u4f7f\u3063\u305frequireJS\u3001backboneJS\u3001highchartsJS\u3068\u30b5\u30fc\u30d0\u53d6\u5f97\u306e\u6a5f\u80fd\u5168\u90e8\u4e57\u305b\u306a\u307e\u3068\u3081\u7684HelloWorld\u3067\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u8a18\u4e8b\u306e\u7d9a\u304d\u3067\u3059\u3002\u3010RequireJS\u3011\u3010BackboneJS\u3011\u3010HighchartsJS\u3011bac [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":975,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[211],"tags":[220,228,227,225,224,213,226,221],"class_list":["post-1010","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-backbonejs","tag-collection","tag-fetch","tag-highchartsjs","tag-model","tag-requirejs","tag-server","tag-view"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1010"}],"version-history":[{"count":1,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1010\/revisions"}],"predecessor-version":[{"id":1015,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1010\/revisions\/1015"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/975"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}