Socket
Book a DemoInstallSign in
Socket

knockout-interpolate

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knockout-interpolate

Knockout binding provider that does a one-time replacement of {{ expression }} blocks with data from the view model.

0.4.0
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

knockout-interpolate

What is this plugin?

This library augments Knockout's default binding provider by adding support for interpolating text while Knockout is visiting each node to determine if it has bindings. This text replacement is designed to be done in a one-time manner (does not react to observables being updated). You would use this functionality in cases where you do want to use text from your view model, but do not need/want the overhead of a binding.

While the replaced text would not react to changes, a common use case may be inside of a container that is bound using the template or with binding such that the entire area would get swapped out. Values support context variables ($root, $parent, etc.) and expressions. For interpolation that converts to a containerless binding check out: http://mbest.github.io/knockout.punches/.

The library also allows similar one-way bindings that are not tracked and do not update using the data-koset attribute. The syntax is the same as data-bind, and currently supports visible, if, value, attr, and css bindings.

Note

The css binding depends on either your browser supporting classList, or jQuery being present. If neither of those conditions is satisfied, any usage of the css binding with data-koset will fail silently.

Examples

<div>First name: {{ first }}</div>
<div>Last name: {{ last }}</div>
<div>Full name: {{ first() + " " + last() }}</div>
<div>User: $root.userName</div>

<div data-koset='visible: x'></div>
<div data-koset='if: y'>XXX</div>
<select><option data-koset='value: z'></option></select>
<a data-koset="attr: { href: '#contacts/details/' + id }">{{ name }}</a>
<a data-koset="css: { active: isActive }">{{ name }}</a>

Once you've loaded the library, you enable it like:

ko.bindingProvider.instance = ko.bindingProvider.interpolate;

FAQs

Package last updated on 31 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.