Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i update the underlying data in colorbox?
    primarykey
    data
    text
    <p>I am trying to combine knockout.js and colorbox in a photo-gallery.</p> <p>I have all photos in an observable array, and the code looks something like this:</p> <pre><code> &lt;script type='text/javascript&gt; function Photo(src, comment) { this.image = src; this.comment = ko.observable(comment); } var view_model = { photos: ko.observableArray([ new Photo('/gallery/img1.jpg', 'Some comment'), new Photo('/gallery/img2.jpg', 'Some other comment'), new Photo('/gallery/img3.jpg', '') ]), current_photo: ko.observable() }; $(document).ready(function(){ $('ul#gallery').colorbox({href: '#photo-detail'}); }); &lt;/script&gt; &lt;script id='photoTemplate' type='text/html'&gt; &lt;li&gt; &lt;img src='{{src}}' /&gt; &lt;div&gt;{{comment}}&lt;/div&gt; &lt;/li&gt; &lt;/script&gt; &lt;body&gt; &lt;ul id='gallery' data-bind='template: "photoTemplate, foreach:photos"'&lt;/ul&gt; &lt;div style='display: none'&gt; &lt;div id='photo-detail'&gt; &lt;img data-bind='attr: { src: current_photo().src }'/&gt; &lt;input type="text" data-bind='value: current_photo().comment'/&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>I update current_photo in the event-handler for colorbox, when a new image loaded. Everything works until i edit a comment.</p> <p>It seems like knockout removes the DOM-element, and replaces it with a new, so when moving to next photo and then back again, colorbox bugs out. If i close colorbox and reinitialize, it works again.</p> <p>Is there a way to update the the data for colorbox, without closing it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload