javascript - Knockout cannot rebind observable -


inside program, use froala rich text editor write texts, put images etc. , specific reasons, create tag ko.observable binding , submit drupal, erasing tag binding before submitting. after can take information drupal again (no tag bindings anymore). so, in order edit information again create same binding again. however, time binding not work anymore. simplified of javascript code below :

$(document).ready(function() {       function create_image_table() {         if (!document.getelementbyid("img_div0"))             $('<div id="img_div0" style="border : 1px solid black;  width=80%"  class="asd row"/>').appendto(document.getelementsbyclassname("fr-element fr-view")[0]);         $('<div id="ilk0" class="my_ilk col-sm-6" contenteditable="false"/>').append($('<div id="caption0" style="font-weight:normal; height: 50px;" data-bind="text: captionname0" data-toggle="modal" data-target="#mymodal" class="caption_class"  contenteditable="false"/>')).appendto($("#img_div0"));         }     function create_image_observables(){         myviewmodel['captionname0'] = ko.observable('caption : ');         ko.applybindings(myviewmodel,document.getelementbyid('caption0'));     }     var myviewmodel = {         edit_fields : function() {             this.captionname0('caption : ' + document.getelementbyid('caption_input').value);         }      };     ko.applybindings(myviewmodel);     document.getelementbyid("editor_content_button").addeventlistener("click", submit);      var images = document.getelementsbyclassname("asd row");     (j=0;j<images.length;j++) {          create_image_table(0, "");         create_image_observables(0, "","","","","");         }     function submit () {         create_image_table(0, "");         create_image_observables(0, "", "", "", "", "");         var content_to_send = document.getelementbyid("img_div0").parentnode.innerhtml.replace(/&lt;/g,"<");          $.ajax({             type: "post",             datatype: 'json',             data: {mycontent: content_to_send, title: "", author: "" },             url: "submit_2.php",             success: function(response) {                 if(response > 0) {                      window.location = ($(this).attr('href') + 'rte_2.php?id='+response).replace("undefined","") ;                 }             }         });     }     $(function() {         $('div#froala-editor').froalaeditor({toolbarbuttons: ['undo', 'redo' , '|', 'bold', 'italic', 'underline', '|' ,'fullscreen', 'inlinestyle', '|', 'insertlink', 'paragraphformat','|', 'insert','inserthtml'],})         }); }); 

in submit_2.php in order erase these tags, use :

$tags= $xpath->query('//div[contains(@id,"ilk")]');  foreach ($tags $tag) {        $tag->parentnode->removechild($tag);     } 

then, information drupal , show them again in same format before (i add tag binding again). binding lost observable feature.

i tried using cleannode , removenode functions inside submit function instead of erasing in submit_2.php, however, got same result again. how can solve problem? in advance.


Comments