javascript - style binding issue when the () are not included -
can please clarify following situation knockout.js style bindings?
if use functions width(), height() bindings successful, when use properties without () bindings not successful. attr binding don`t have use ().
successful attr , style bindigs:
<div class="container" id="container" data-bind="foreach: nodes"> <div class="node" data-bind="attr:{id:id}, style: {width: width() + 'px', height: height() + 'px', left: positionleft() + 'px', top: positiontop() + 'px'}"> <span data-bind="text:name"></span> <div class="ep"></div> </div>
attr bindings applied style bindings not successful
<div class="container" id="container" data-bind="foreach: nodes"> <div class="node" data-bind="attr:{id:id}, style: {width: width + 'px', height: height + 'px', left: positionleft + 'px', top: positiontop + 'px'}"> <span data-bind="text:name"></span> <div class="ep"></div> </div>
if dealing observables, need call them function retrieve value, if using them in expression (like width() + 'px'
).
if passing observable (not type of expression), bindings smart enough unwrap observable.
so, text: myobservable
fine, text: myobservable() + '!'
require parens.
Comments
Post a Comment