flatiron / plates

Light-weight, logic-less, DSL-free, templates for all javascript environments!
MIT License
831 stars 69 forks source link

howto set attribute and value at the same time to the same value? #89

Open framlin opened 11 years ago

framlin commented 11 years ago

html = data = [{target:1},{target:2}]

Plates.bind(html, data);

what I want to have as a mapping/binding-result is:

12

The problem seems to be, that I did not get, how to set a tag-attribute AND the tag-valuue at the same step. I have a played a little with map, but I only have the attribute set OR the value, but never both. Here is one other example:

var data = [{href: 'a', msg: 1}, {href: 'b', msg: 2}];
var html = '<div href="#"></div><div class="msg"></div>';
var Plates = require('plates');
var map = Plates.Map();
map.where('href').is('#').insert('href');
//var result = Plates.bind(html, data);
//console.log(result);
//<div href="#"></div><div class="msg">1</div><div href="#"></div><div class="msg">2</div>

//var result = Plates.bind(html, data, map);
//console.log(result);
//<div href="a"></div><div class="msg"></div><div href="b"></div><div class="msg"></div>

Is there any way?