Closed Kwooda closed 4 years ago
Thanks for providing this, but I wasn't able to test the above sample... If you think that this is a bug in JsRender, or a missing feature, and not simply a bug in your sample, can you provide a minimalist sample to repro the problem? The above sample includes some irrelevant content (e.g. {{if}}) tags etc.) and is incomplete (no data provided) so can't be directly tested.
The best would be to create a jsfiddle example with an outer {{props}} loop and an inner one, with simple data, and nothing else - and indicate what you consider would be expected behavior, as compared to the actual behavior.
Given that I will investigate.... Thanks!
It’s pretty straightforward, but ok. I’ll try to get to it next week. I worked around it by calling a helper to generate the desired HTML rather than relying on the template. {{props}} was simply not giving me any functions in the inner loop. The only {{if}} there was to display some text and is irrelevant to the example.
Sent from my iPhone
On Feb 7, 2020, at 6:02 PM, Boris Moore notifications@github.com wrote:
If you think that this is a bug in JsRender, or a missing feature, and not simply a bug in your sample, you need to provide a minimalist sample to repro the problem. The above sample includes irrelevant content (e.g. {{if}}) tags etc.) and is incomplete (no data provided).
The best would be to create a jsfiddle example with an outer {{props}} loop and in inner one, with simple data, and nothing else. Then indicate clearly what you consider would be expected behavior, as compared to the actual behavior.
Given that I will try to look more closely at it.... Thanks!
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Well I tried this:
<script id="myTmpl" type="text/x-jsrender">
{{props foo}}
{{:prop}}
{{props ~root.bar}}
{{:prop}}
{{/props}}
{{props ~root.ob}}
{{:key}}
{{:prop.is}}
{{/props}}
{{/props}}
</script>
<div id="page"></div>
<script>
var data = {
foo: function(){ return "XX"},
bar: function(){ return "XX"},
ob: {sub:function(){ return "XX"}}
};
data.ob.sub.is="YES";
data.foo.a="A";
data.foo.b="B";
data.bar.x="X";
data.bar.y="Y";
var myTmpl = $.templates("#myTmpl"),
html = myTmpl(data);
$("#page").html(html);
</script>
and the output was "A X Y sub YES B X Y sub YES " (modulo white space)
So function objects and properties seem to work correctly with nested {{props}} loops.... I'm not seeing any issue, so far...
My testing indicates that {{props}} works correctly, including when applied to a function (as object) and when some of the properties are of type function. So I will close this issue.
If you have an example which indicates otherwise, can you reply here, with the example code and data, and and we can re-open this issue... Thanks...
In JavaScript, functions are first-class objects, meaning they can have properties. I have an environment where modules are defined by adding a function to a namespace - the function is the module's primary entry point, but the function, itself, may have many other properties, many of which may be functions, themselves.
I have a nested {{props}} loop in a template to iterate over all the modules, and the inner {{props}} loop to list all the properties of a module (function). But the inner loop is not listing any properties. If a property on the outer loop resolves to an object, the inner loop lists its properties - the inner loop just isn't listing any properties if the outer property is a function.
Even when ~root.NS[key] resolves to an object (not a function), it's not listing any of the function properties of that object. I even tried setting noFunctions=false.