BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
855 stars 130 forks source link

for tag with range and data-linked tr give error when removing object from array #442

Closed johan-ohrn closed 4 years ago

johan-ohrn commented 4 years ago

Run this fiddle with the console open.

Here's the code:

var vm = {
    arr: [1,2,3,4]
};

$.templates("\
    <table><tbody>\
    {^{for arr start=0 end=4 }}\
    <tr data-link='{on blah}'><td>x</td></tr>\
    {{/for}}\
    </tbody></table>\
").link("#ph", vm);

setTimeout(function() {
    $.observable(vm.arr).remove(0, 1)
});

Error is:

jsviews.js:6517 Uncaught TypeError: Cannot read property 'removeChild' of null
    at removeViewBinding (jsviews.js:6517)
    at clean (jsviews.js:6461)
    at Function.cleanData (jsviews.js:7827)
    at init.remove (jquery-1.9.1.js:5988)
    at init.$.fn.<computed> [as remove] (jsviews.js:7871)
    at removeView (jsviews.js:7048)
    at View.theView.removeViews (jsviews.js:7106)
    at View.arrayChangeHandler (jsviews.js:4803)
    at Tag.onArrayChange (jsviews.js:7545)
    at Object.arrayBindings.<computed> [as cb] (jsviews.js:7579)

The error goes away if I remove the data-link attribute from the tr element or if I remove the start/end attributes on the for tag. It also seem to be related to the fact that data-link is placed on a tr element.

BorisMoore commented 4 years ago

Thanks for catcihng/reporting this Johan! I am looking at a probable fix. I'll keep you posted....

BorisMoore commented 4 years ago

Hi Johan. Here is an update that should fix both this issue, and https://github.com/BorisMoore/jsviews/issues/444, (and includes the previous fix for https://github.com/BorisMoore/jsviews/issues/440):

download.zip

Let me know if it works for you.

johan-ohrn commented 4 years ago

I can confirm that this works. Thanks!

BorisMoore commented 4 years ago

Thanks for verifying. I'll close this issue once we publish the update...

BorisMoore commented 4 years ago

Fixed in v1.0.6