Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : can.view(template, data) only return a Deferred? Docs say fragment is returned?

$
0
0
The docs aren't clear about this, but this has been a feature since CanJS 1.x that if your view data is a deferred, you will get a deferred back.  Example from my Chrome console:

$("<script type='text/mustache' id='fooscript'><span>foo! {{text}}</span></script>").appendTo(document.body)
[
  1. <script type=​"text/​mustache" id=​"fooscript"><span>foo! {{text}}</span></script>
]
can.view("fooscript", new $.Deferred().resolve({ text : "bar"}))
Object {resolvefunctionresolveWithfunctionrejectfunctionrejectWithfunctionnotifyfunction}
can.view("fooscript", { text : "bar"})
  1. #document-fragment


 this is not the case when your view is in the form of a function, though:

stache = can.view.mustache("<span>foo! {{text}}</span>")
function () { return $view.frag(renderer.render.apply(this, arguments)); }
can.view(stache, { text : "Bar" })
  1. #document-fragment
can.view(stache, $.when({text : "Bar" }))
  1. #document-fragment


Viewing all articles
Browse latest Browse all 3491

Latest Images

Trending Articles



Latest Images