{"id":969,"date":"2019-06-15T21:43:27","date_gmt":"2019-06-15T12:43:27","guid":{"rendered":"https:\/\/ito-u-oti.com\/?p=969"},"modified":"2019-06-15T21:49:55","modified_gmt":"2019-06-15T12:49:55","slug":"post-969","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=969","title":{"rendered":"\u3010RequireJS\u3011\u3010BackboneJS\u3011requireJS\u304b\u3089backboneJS\u3092\u4f7f\u3046\uff08View+Model\uff09"},"content":{"rendered":"\n<p>\u524d\u56de\u304b\u3089\u306e\u7d9a\u304d\u3067\u3059\u3002<br><a href=\"https:\/\/ito-u-oti.com\/post-948\/\">\u3010RequireJS\u3011\u3010BackboneJS\u3011requireJS\u304b\u3089backboneJS\u3092\u4f7f\u3046\uff08View\uff09<\/a><br>\u4eca\u56de\u306fBackboneJS\u306eView\u304b\u3089Model\u3092RequireJS\u3067\u8aad\u307f\u8fbc\u3093\u3067\u4f7f\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\">\u6982\u8981<\/h3>\n\n\n\n<p>requireJS\u3092\u4f7f\u7528\u3057\u3066BackboneJS\u3068\u305d\u306e\u4f9d\u5b58\u30d5\u30a1\u30a4\u30eb(jquery\u3001underscore\uff09\u3001Model\u3092\u8aad\u307f\u8fbc\u307f\u3001View\u3092\u4f5c\u3063\u3066index.html\u306bModel\u306e\u30c6\u30ad\u30b9\u30c8\u3092\u8868\u793a\u3055\u305b\u308b\u3002<\/p>\n\n\n\n<h3 id=\"outline__1_2\" 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=\"271\" height=\"297\" src=\"https:\/\/ito-u-oti.com\/wp-content\/uploads\/2019\/06\/013_backboneJS1.png\" alt=\"\" class=\"wp-image-989\"\/><\/figure>\n\n\n\n<h2 id=\"outline__2\" class=\"wp-block-heading\">requireJS\u3067backboneJS\u3068\u3001Model\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b<\/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;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\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    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    },\n    shim: {\n        'backbone' : {\n            deps: &#x5B;'underscore', 'jquery'],\n            exports: 'Backbone'\n        }\n    }\n});\n<\/pre><\/div>\n\n\n<p>backboneJS\u306e\u4f9d\u5b58\u95a2\u4fc2\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\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        defaults: {\n            &quot;text&quot;:&quot;Hello World Backbone!!&quot;\n        }\n    });\n\n    return HelloWorldModel;\n});\n<\/pre><\/div>\n\n\n<p>backboneJS\u306eModel\u3068\u3057\u3066\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002<br>text\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u4e2d\u306b\u300cHello World Backbone!\u300d\u3068\u3044\u3046\u6587\u7ae0\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h3 id=\"outline__2_4\" 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'], function(backbone, helloWorldModel) {\n    \/\/view\u3068\u3057\u3066\u9069\u5207\u306a\u5206\u89e3\u3092\u3059\u308b\n\n    var model = new helloWorldModel();\n    \n    var HelloWorldView = backbone.View.extend({\n        el: $('.hoge'),\n        initialize: function() {\n            this.render();\n        },\n        render: function() {\n            var text = model.get(&quot;text&quot;);\n            $(this.el).html(_.template($('#hello-template').text())({ &quot;text&quot;: text}));\n        }\n    });\n    new HelloWorldView();\n});\n<\/pre><\/div>\n\n\n<p>require\u306b\u6ce8\u76ee\u3057\u3066\u4e0b\u3055\u3044\u3002<br>\u307e\u305a\u3001backboneJS\u306e\u6a5f\u80fd\u3092\u4f7f\u7528\u3059\u308b\u306e\u3067config\u3067\u8a2d\u5b9a\u3057\u305fbackbone\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<br>\u307e\u305f\u3001model\u3092\u4f7f\u7528\u3059\u308b\u306e\u3067\u76f8\u5bfe\u30d1\u30b9\u3067HelloWorldModel\u3092\u6307\u5b9a\u3057\u3066\u547c\u3073\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>View\u3067\u306f\u307e\u305aModel\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3059\u308b\u3068\u3053\u308d\u304b\u3089\u59cb\u307e\u308a\u307e\u3059\u3002<br>initialize\u3067\u521d\u671f\u51e6\u7406\u306e\u969b\u306brender\u3092\u547c\u3073\u51fa\u3057\u3001\u305d\u306e\u4e2d\u3067model\u306etext\u30d5\u30a3\u30fc\u30eb\u30c9\u304b\u3089\u5024\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<br>\u305d\u3057\u3066\u3001template\u3092\u547c\u3073\u51fa\u3057\u3066hoge\u30af\u30e9\u30b9\u306e\u8981\u7d20\u306e\u4e2d\u306b\u633f\u5165\u3057\u3064\u3064text\u3092template\u306b\u57cb\u3081\u8fbc\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<h3 id=\"outline__2_5\" class=\"wp-block-heading\">\u8868\u793a<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"799\" height=\"376\" src=\"https:\/\/ito-u-oti.com\/wp-content\/uploads\/2019\/06\/012_backboneJS1-1.png\" alt=\"\" class=\"wp-image-997\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u304b\u3089\u306e\u7d9a\u304d\u3067\u3059\u3002\u3010RequireJS\u3011\u3010BackboneJS\u3011requireJS\u304b\u3089backbo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":972,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[211],"tags":[220,224,213,222,223,221],"class_list":["post-969","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-backbonejs","tag-model","tag-requirejs","tag-template","tag-underscore","tag-view"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/969","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=969"}],"version-history":[{"count":4,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/969\/revisions"}],"predecessor-version":[{"id":998,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/969\/revisions\/998"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/972"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}