Skip to content


Subversion checkout URL

You can clone with
Download ZIP


elem argument may be undefined for jsViewsData() during an ArrayObservable.remove() #116

fuwjax opened this Issue · 5 comments

3 participants


When removing an element from an array using $.observable(array).remove(index, 1), the following error is displayed in the firebug console:

TypeError: elem is undefined
jqDataOnElem = $.cache[elem[$.expando]]; jquery.views.js (line 808)

I suspect it has something to do with the inner {{for}} in the following template, as this is the template bound to the array:

<script id="metricTemplate" type="text/x-jsrender">
    <tr title="{{:description}}" class="metricInfo
        {{for labels}}
    "><td>{{:name}}</td><td>{{:expression}}</td><td><a href="#" role="button" class="removeMetric btn" title='Delete "{{:name}}" Metric' data-remove-text="Delete Metric" data-removing-text="<span class='inline white spinner'></span> Deleting..."><i class="icon-remove"></i></a></td></tr>

I have a screenshot of the stacktrace from firebug, if it would be useful. At the very least, I was able to avoid the error by changing line 808 to the following:

jqDataOnElem = elem && $.cache[elem[$.expando]];


JsViews does not support using tags like {{for}} or {{if}} within HTML attribute markup. (You can do so if you are just using JsRender, but with JsViews it needs to add data binding info to the DOM elements, and this will only work within element content.)
For you scenario above you use a helper function, like this:

    concat: function(items) {
        var result = "";
        $(items).each(function(){ result += this; });
        return result; 

and then write ...class="metricInfo{{:~concat(labels)}}">...


I'm running into this exact same problem, but am not using tags in html attributes.

I'm putting {{for #data tmpl="#template" link=false /}} in a template that is bound to elements of an array (similar situation as above), and getting the same error, only on removes. The child template uses no data-link attributes, although uses {{:variable}} in html attributes.

Anyway, by changing the above to have link=true, everything works as expected, and that's a good enough solution for me, but was definitely not expected. I will try to add a better example when I get a chance.


This unfortunately bit me again. Basically, if you have a template used by a {{for link=true}} tag, every {{for}} tag it uses, or any subtemplates it uses, must have the link=true attribute. Trying to make the link=false optimization is unfortunately not possible, although I hope this can be fixed at some point.

@BorisMoore BorisMoore referenced this issue from a commit
@BorisMoore Commit 30. (Beta Candidate)
This provides a fix for #89, #116, #148 and #149.
It is also a candidate for Beta. If no significant new bugs are
encountered then it will be used to provide an official beta version.

This should now be fixed, with commit 30.



@BorisMoore BorisMoore closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.