{"id":1409,"date":"2022-08-30T15:16:17","date_gmt":"2022-08-30T15:16:17","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/15\/how-to-use-backbone-collection-to-fetch-this-json-result-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:17","modified_gmt":"2022-08-30T15:16:17","slug":"how-to-use-backbone-collection-to-fetch-this-json-result-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-use-backbone-collection-to-fetch-this-json-result-collection-of-common-programming-errors\/","title":{"rendered":"how to use Backbone Collection to fetch this JSON result?-Collection of common programming errors"},"content":{"rendered":"<p>I have the following JSON reply<\/p>\n<pre><code>{\n   \"results\":[\n      {\n         \"Product\":{\n            \"id\":\"1\",\n            \"short_name\":\"Infra - 2200 CAS Sma SIMO onl [DAS.1.1]\",\n            \"serial_number\":\"DAS.1.1\",\n            \"created_by\":\"Wesley Jace Tan\",\n            \"modified_by\":\"Wesley Jace Tan\",\n            \"created\":\"2013-02-11 07:58:20\",\n            \"modified\":\"2013-02-11 07:58:20\",\n            \"full_name_type\":\"2200\",\n            \"full_name_cas_stk\":\"CAS\",\n            \"full_name_size\":\"Small\",\n            \"full_name_simo_mimo\":\"SIMO only\",\n            \"full_name_product_code\":\"(2961-737)\",\n            \"uom\":\"lot\",\n            \"material\":\"Infra\"\n         },\n         \"Price\":[\n            {\n               \"id\":\"1\",\n               \"product_id\":\"1\",\n               \"source_file\":\"LTE Test File.xls\",\n               \"for_financial_year\":\"FY12_13\",\n               \"created_by\":\"Wesley Jace Tan\",\n               \"modified_by\":\"Wesley Jace Tan\",\n               \"created\":\"2013-02-11 07:58:20\",\n               \"modified\":\"2013-02-11 07:58:20\",\n               \"gross_unit\":\"50.00\",\n               \"gross_total_value\":\"0.00\",\n               \"gross_total_formula\":\"=K12*J12\",\n               \"incentive_value\":\"5\",\n               \"incentive_formula\":\"5\",\n               \"net_price_unit\":\"0.00\",\n               \"net_price_total_value\":\"0.00\",\n               \"net_price_total_formula\":\"=N12*J12\"\n            }\n         ]\n      },\n      {\n         \"Product\":{\n            \"id\":\"2\",\n            \"short_name\":\"Infra - 2200 CAS Sma SIMO to  [DAS.1.2]\",\n            \"serial_number\":\"DAS.1.2\",\n            \"created_by\":\"Wesley Jace Tan\",\n            \"modified_by\":\"Wesley Jace Tan\",\n            \"created\":\"2013-02-11 07:58:20\",\n            \"modified\":\"2013-02-11 07:58:20\",\n            \"full_name_type\":\"2200\",\n            \"full_name_cas_stk\":\"CAS\",\n            \"full_name_size\":\"Small\",\n            \"full_name_simo_mimo\":\"SIMO to MIMO Retrofit\",\n            \"full_name_product_code\":\"(2961-737)\",\n            \"uom\":\"lot\",\n            \"material\":\"Infra\"\n         },\n         \"Price\":[\n            {\n               \"id\":\"2\",\n               \"product_id\":\"2\",\n               \"source_file\":\"LTE Test File.xls\",\n               \"for_financial_year\":\"FY12_13\",\n               \"created_by\":\"Wesley Jace Tan\",\n               \"modified_by\":\"Wesley Jace Tan\",\n               \"created\":\"2013-02-11 07:58:20\",\n               \"modified\":\"2013-02-11 07:58:20\",\n               \"gross_unit\":\"11.00\",\n               \"gross_total_value\":\"0.00\",\n               \"gross_total_formula\":\"=K13*J13\",\n               \"incentive_value\":\"24\",\n               \"incentive_formula\":\"24\",\n               \"net_price_unit\":\"0.00\",\n               \"net_price_total_value\":\"0.00\",\n               \"net_price_total_formula\":\"=N13*J13\"\n            }\n         ]\n      },\n      {\n         \"Product\":{\n            \"id\":\"3\",\n            \"short_name\":\"Infra - 2200 CAS Sma Full MIM [DAS.1.3]\",\n            \"serial_number\":\"DAS.1.3\",\n            \"created_by\":\"Wesley Jace Tan\",\n            \"modified_by\":\"Wesley Jace Tan\",\n            \"created\":\"2013-02-11 07:58:20\",\n            \"modified\":\"2013-02-11 07:58:20\",\n            \"full_name_type\":\"2200\",\n            \"full_name_cas_stk\":\"CAS\",\n            \"full_name_size\":\"Small\",\n            \"full_name_simo_mimo\":\"Full MIMO\",\n            \"full_name_product_code\":\"(2961-737)\",\n            \"uom\":\"lot\",\n            \"material\":\"Infra\"\n         },\n         \"Price\":[\n            {\n               \"id\":\"3\",\n               \"product_id\":\"3\",\n               \"source_file\":\"LTE Test File.xls\",\n               \"for_financial_year\":\"FY12_13\",\n               \"created_by\":\"Wesley Jace Tan\",\n               \"modified_by\":\"Wesley Jace Tan\",\n               \"created\":\"2013-02-11 07:58:20\",\n               \"modified\":\"2013-02-11 07:58:20\",\n               \"gross_unit\":\"12.00\",\n               \"gross_total_value\":\"0.00\",\n               \"gross_total_formula\":\"=K14*J14\",\n               \"incentive_value\":\"5\",\n               \"incentive_formula\":\"5\",\n               \"net_price_unit\":\"0.00\",\n               \"net_price_total_value\":\"0.00\",\n               \"net_price_total_formula\":\"=N14*J14\"\n            }\n         ]\n      }\n   ]\n}\n<\/code><\/pre>\n<p>The url to retrieve the above data is \/products\/index.json<\/p>\n<p>The url to retrieve page 2 of products data is \/products\/index.json\/page:2<\/p>\n<p>I have written the following as the Collection<\/p>\n<pre><code>\n    (function ($) {\n        window.AppView = Backbone.View.extend({\n            el: $(\"body\")\n        });\n        var appview = new AppView;\n\n        var Products = Backbone.Collection.extend({\n            model: Product, \n            url: '\/products\/index.json'\n        });\n\n        Products.fetch();\n    })(jQuery);\n\n<\/code><\/pre>\n<p>I think I have written the <code>Products<\/code> Collection wrongly.<\/p>\n<p>Please advise.<\/p>\n<p><strong>UPDATE<\/strong><\/p>\n<p>This is my new code http:\/\/jsfiddle.net\/Cw6PT\/<\/p>\n<p>This is the error message I now have: Uncaught TypeError: Object function (){return c.apply(this,arguments)} has no method &#8216;fetch&#8217;<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-15 09:09:59. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have the following JSON reply { &#8220;results&#8221;:[ { &#8220;Product&#8221;:{ &#8220;id&#8221;:&#8221;1&#8243;, &#8220;short_name&#8221;:&#8221;Infra &#8211; 2200 CAS Sma SIMO onl [DAS.1.1]&#8221;, &#8220;serial_number&#8221;:&#8221;DAS.1.1&#8243;, &#8220;created_by&#8221;:&#8221;Wesley Jace Tan&#8221;, &#8220;modified_by&#8221;:&#8221;Wesley Jace Tan&#8221;, &#8220;created&#8221;:&#8221;2013-02-11 07:58:20&#8243;, &#8220;modified&#8221;:&#8221;2013-02-11 07:58:20&#8243;, &#8220;full_name_type&#8221;:&#8221;2200&#8243;, &#8220;full_name_cas_stk&#8221;:&#8221;CAS&#8221;, &#8220;full_name_size&#8221;:&#8221;Small&#8221;, &#8220;full_name_simo_mimo&#8221;:&#8221;SIMO only&#8221;, &#8220;full_name_product_code&#8221;:&#8221;(2961-737)&#8221;, &#8220;uom&#8221;:&#8221;lot&#8221;, &#8220;material&#8221;:&#8221;Infra&#8221; }, &#8220;Price&#8221;:[ { &#8220;id&#8221;:&#8221;1&#8243;, &#8220;product_id&#8221;:&#8221;1&#8243;, &#8220;source_file&#8221;:&#8221;LTE Test File.xls&#8221;, &#8220;for_financial_year&#8221;:&#8221;FY12_13&#8243;, &#8220;created_by&#8221;:&#8221;Wesley Jace Tan&#8221;, &#8220;modified_by&#8221;:&#8221;Wesley Jace Tan&#8221;, &#8220;created&#8221;:&#8221;2013-02-11 07:58:20&#8243;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1409","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1409"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1409\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}