MajidTaheri
MajidTaheri

Reputation: 3983

Data-binding in Jade without client-side Javascript

I am binding fields with name , value attributes. but it is not comfortable.

input(name='user[name]', value='#{user.name}')

I want data-binding similar to knockout.js but without loading javascript in the client (traditional mobile devices). Something like the following code:

 input(databind='username[value]')

Upvotes: 4

Views: 2529

Answers (1)

joshp
joshp

Reputation: 1892

A big part of the power of knockout.js is "two way binding", detecting changes and events on DOM elements and reflecting them in the Model. This part is not possible without loading javascript.

So I assume you are asking about some form of one way binding when generating html to send to the client.

This makes me wonder what benefits you seek. Is it simply a preference for a different style of coding?

Knockout.js's data binding is presented as an extensible set of 'bindings' each tailored to a specific purpose, to make a specific range of use scenarios convenient. knockout's foreach, or repeat bindings can be convenient for generating lists or tables, for example. To me, knockout's greatest strength is the ease of creating new bindings to suit your specific needs.

For what it's worth here are some ideas...in no particular order.

  1. You might be able to use jade mixins and blocks to define some simple reusable bindings that fit common use scenarios.
  2. Look at other template libraries that fit your server side environment, see if there's something you like better than jade.
  3. A template library with an extension mechanism (EJS filters, Mustache lambdas, JSP custom tags) would allow you to create some frequently used bindings for your use scenarios and reuse them.

Probably the best thing to do is to be more specific about the benefits you want. That might inspire some better responses here.

Upvotes: 2

Related Questions