Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ko-templated

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ko-templated

Binding for knockoutJs. Allows imlicit templates, i.e. load with ajax from templates dir or attach template source to ViewModule as string.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

###ko-templated is a binding for knockout.

##Description

Allows asynchronous loading of templates. Uses jQuery for template loading. The main idea is to use view model's or sub model's constructor name as name of template. Binding encourages using of new for constructing view models or sub models.
So when you try to use it on plain javascript object it will load "Object.tmpl". You may override naming convention by defining templateName property in object. It may also be observable.

By default binding loads template from 'templates' sub directory. You may override it with templatePath property, String or observable.

##Code

Here is sample code in viewModel.js:

function SubModel(){
  this.anotherField = ko.observable('World !')
}

function ViewModel(){
  this.someField = ko.observable('Hello ');
  this.someSubModel = new SubModel();
}

ko.applyBindings(new ViewModel());

##Markup Sample markup in main file:

<!DOCTYPE HTML>
<html>
<head>
    <title>Sample ko-templated binding</title>
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
    <script src='http://knockoutjs.com/downloads/knockout-2.3.0.js'></script>
    <script src='ko-templated.js'></script>
    <script src='viewModel.js'></script>
</head>
<body data-bind='templated: $data'>
</body>
</html>

Template for ViewModel in templates/ViewModel.tmpl:

<span data-bind='text:someField'></span>
<!-- ko templated: someSubModel -->
<!-- /ko -->

Template for SubModel in templates/SubModel.tmpl:

<span data-bind='text:anotherField'></span>

Keywords

FAQs

Package last updated on 17 Oct 2014

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc