{"id":1476,"date":"2022-08-30T15:16:51","date_gmt":"2022-08-30T15:16:51","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/23\/how-to-update-edit-record-in-emberjs-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:16:51","modified_gmt":"2022-08-30T15:16:51","slug":"how-to-update-edit-record-in-emberjs-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-update-edit-record-in-emberjs-collection-of-common-programming-errors\/","title":{"rendered":"How to update\/edit record in emberjs?-Collection of common programming errors"},"content":{"rendered":"<p>I have collected data from fixture and displayed in form of table.<\/p>\n<p>Also,i have added two column one is edit another is delete now i want to edit specific row.<\/p>\n<p>On click of edit i have populated data on modal window with one update button and i want to update changes on click of update.<\/p>\n<p>Here is my code : Store :<\/p>\n<pre><code>Grid.Store = DS.Store.extend({adapter: 'DS.FixtureAdapter'});\n<\/code><\/pre>\n<p>Router:<\/p>\n<pre><code>        Grid.Router.map(function () {\n      this.resource('mainview', { path: '\/' });                       \n    });  \n    Grid.MainviewRoute = Ember.Route.extend({\n          model: function () {\n            return Grid.ModalModel.find();\n          }\n    });\n<\/code><\/pre>\n<p>Model :<\/p>\n<pre><code>    Grid.ModalModel =  DS.Model.extend({\n    fname: DS.attr('string'),\n    lname: DS.attr('string'),\n    email: DS.attr('string'),\n    contactno: DS.attr('string'),\n    gendertype: DS.attr('boolean'),\n    contactype: DS.attr('number')\n});\n\nGrid.ModalModel.FIXTURES = [\n                       {\n                         id: 1,\n                         fname: \"sachin\",\n                         lname: \"gh\",\n                         email: \"gh\",\n                         contactno: \"4542154\",\n                         gendertype: true,\n                         contactype: 1\n                       },\n                       {\n                         id: 2,\n                         fname: \"amit\",\n                         lname: \"gh\",\n                         email: \"gh\",\n                         contactno: \"4542154\",\n                         gendertype: true,\n                         contactype: 1\n                       },\n                       {\n                         id: 3,\n                         fname: \"namit\",\n                         lname: \"gh\",\n                         email: \"gh\",\n                         contactno: \"4542154\",\n                         gendertype: true,\n                         contactype: 1\n                       }\n                      ];\n<\/code><\/pre>\n<p>Controller :<\/p>\n<pre><code>Grid.MainviewController = Ember.ArrayController.extend({\n    contentChanged: function() {\n        this.get('content').forEach(function(item){\n          var serializer = DS.RESTSerializer.create();\n          var json_data = serializer.serialize(item);\n          console.log(JSON.stringify(json_data));\n        });\n      }.observes('content.@each'),\n    showmodal: function(){    \n          $('#modal').modal(); \n    },\n    showeditmodal: function(){\n        var rowindex_table = 1;\n        var contactype = 0;\n          var post = Grid.ModalModel.find(rowindex_table);\n          var serializer = DS.RESTSerializer.create();\n          var cont_edit_data = serializer.serialize(post);\n          console.log(JSON.stringify(cont_edit_data));\n\n          this.set('obj_form_edit_data.cont_data.fname', cont_edit_data[\"fname\"]);\n            this.set('obj_form_edit_data.cont_data.lname', cont_edit_data[\"lname\"]);\n            this.set('obj_form_edit_data.cont_data.email', cont_edit_data[\"email\"]);\n            this.set('obj_form_edit_data.cont_data.contactno', cont_edit_data[\"contactno\"]);\n            if(cont_edit_data[\"gendertype\"] == true){\n                this.set('male', true);\n                $(\".cssmale\").addClass(\"active\");\n            }else{\n                this.set('female', true);\n                $(\".cssfemale\").addClass(\"active\");\n            }\n            $('.selectpicker').val(cont_edit_data['contactype']);\n            $('.selectpicker').selectpicker('render');\n            $('#editmodal').modal();\n    },\n    isMale: false,\n    isFemale: false,\n    obj_form_edit_data : Ember.Object.create({\n        cont_data:{\n            fname : \"\",\n            lname : \"\",\n            email : \"\",\n            contactno : \"\",\n            gendertype : \"\",\n            contactype : 0\n        }\n    }),     \n    gendertype: function(){\n        this.set('isMale', !this.get('isMale'));\n    },\n    savecontact: function(){\/\/save data in local storage\n        var fname = this.obj_form_edit_data.get('cont_data.fname');\n        var lname = this.obj_form_edit_data.get('cont_data.lname');\n        var email = this.obj_form_edit_data.get('cont_data.email');\n        var contactno = this.obj_form_edit_data.get('cont_data.contactno');\n        var gendertype = ((this.get('isMale') == true) ? true : false);\n        var contactype = $(\".selectpicker\").text();\n        \/\/Clear view first\n        this.set('obj_form_edit_data.cont_data.fname', '');\n        this.set('obj_form_edit_data.cont_data.lname', '');\n        this.set('obj_form_edit_data.cont_data.email', '');\n        this.set('obj_form_edit_data.cont_data.contactno', '');\n        this.set('isMale',false);\n        this.set('isFemale',false);\n        $('.selectpicker').val('0');\n        $('.selectpicker').selectpicker('render');\n\n        Grid.ModalModel.createRecord({  \n          fname: fname,\n          lname: lname,\n          email: email,\n          contactno: contactno,\n          gendertype: gendertype,\n          contactype: contactype\n        });\n        this.get('store').commit(); \n    },\n    updatecontact: function(){\n        this.get('store').commit();\n    }\n\n\nupdatecontact is used to update record on click of update button but it is throwing an error \nUncaught TypeError: Object [object Object] has no method 'commit'\n<\/code><\/pre>\n<p>Can anyone tell me how to update record in such case?<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-23 07:54:33. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have collected data from fixture and displayed in form of table. Also,i have added two column one is edit another is delete now i want to edit specific row. On click of edit i have populated data on modal window with one update button and i want to update changes on click of update. [&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-1476","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1476","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=1476"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1476\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}