Code Monkey home page Code Monkey logo

knockout.namespaces's Introduction

Knockout.namespaces

Multiple KnockoutJS ViewModels (separated by namespaces). Compatible with the global namespace as well (standard global 'data-bind' ViewModel).

Download

Try

$ git clone git://github.com/hunterloftis/knockout.namespaces.git
$ cd knockout.namespaces/examples
$ open simple.html

Code

<script src="knockout-latest.js"></script>
<script src="knockout.namespaces-latest.js"></script>
...
<span data-bind-user="text: name">
<span data-bind="text: title"> <!-- works with regular bindings -->
...
<script>
  ko.applyBindings(globalViewModel);
  ko.applyBindings(userViewModel, 'user');
</script>

Use cases

  • Multiple ViewModels
  • Ajaxed ViewModels
  • Loosely coupled architecture
  • Dynamic binding
  • Data-bound controls and modules

Templates

Namespaced templates are a work-in-progress. Check out /examples/templates.html. They work for common use cases, but such actions as nesting multiple templates of different namespaces together may have unpredictable results. I would love some help coming up with a solution.

Related

knockout.namespaces's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

knockout.namespaces's Issues

Error in example

With the latest code, I get the error: 'Cannot call method 'slice' of undefined', which corresponds to this line: 'var namespace = arguments[6].slice(1);' I get this error when viewing the file templates.html within a cloned copy of the repo.

I found this while debugging a different issue related to templates.

Knockout v1.3+ breaks

Knockout's applyBindingsToNode has changed significantly since 1.2. I didn't see an easy way to fix it, so I thought I'd at least log the issue here.

Doesn't work

When I load the plugin an error is thrown:

b.getBindingAttribute is not a function

Doesn't work inside templates?

Does the namespacing work inside templates? The following code doesn't seem to be working:

<ul data-bind-users='template: { name : "UserTmpl", foreach: users }'></ul>
<script type='text/html' id='UserTmpl'>
<li>
  <input type='text' data-bind-users='value: name' /> 
  <p data-bind-users='text: name'></p>
</li>
</script>

You can find the complete example here: https://github.com/Enome/knockout.namespaces/blob/master/examples/simple.html which is a fork of your simple.html

Friendly Greetings

Not maintained any more?

just by including it: "Uncaught TypeError: undefined is not a function", last issue closed: 2011.

issue with templates

From looking at the templates.html example file, this should work, but for some reason, it doesn't.

In the global namespace, I render a template that has bindings for a namespace 'email' within it. These bindings for 'email' do not get attached. I have matching versions of jquery, jquery.tmpl, and knockout from the example in the repo. Let me know what other info you'd like for debugging and I'll send it over.

Question: how to use the non-global viewmodel in an {{IF}} block?

How do I use the non-global viewmodel in an {{IF}} block? For instance, in the code below, nested_children is a property on the unit view model, not the global view model. How do I get it to work?

  {{if nested_children == false}}
    <p> stuff </p>
  {{else}}
    <p> other stuff </p>
  {{/if}}

Thanks!
Scott

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.