Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug using mapping, all unmentioned attributes are lost #76

Open
lashleigh opened this issue Jul 28, 2012 · 1 comment
Open

Bug using mapping, all unmentioned attributes are lost #76

lashleigh opened this issue Jul 28, 2012 · 1 comment

Comments

@lashleigh
Copy link

As shown in this jsfiddle. I wanted to add a link to a list of users and found that if I try to use a Plates.Map to get the link right none of the other user data gets populated. However, I could make it work by extending the map to include the other data.

var collection = [
  {id: 1, 'name': 'Louis CK'},
  {id: 2, 'name': 'Andy Kindler'},
  {id: 3, 'name': 'Greg Giraldo'}
];

var html = "<a href='/users/ID'><span class='name'>NAME</span></a></br>";
var map = Plates.Map().where('href').has(/ID/).insert('id');

var list1 = Plates.bind(html, collection, map);  //Correctly creates the href but name stays NAME
var list2 = Plates.bind(html, collection);       //Correctly populates name but of course the href is unchanged

// If I now extend the map to explicitly include name it will work as expected
map.class('name').to('name')
var list3 = Plates.bind(html, collection, map);  //The new map correctly creates the link and populates the name

I am very surprised that I had to explicitly include what I expected to be the default instructions in order to get the name to populate correctly. Is this a bug, or am I just not understanding how plates should work by default?

Thanks

@heapwolf
Copy link
Contributor

The way I would have done this is shown below.

But what i think you are saying is that Plates should have a set of default mappings; for instance, in your case, you want name (in the data) to automatically map to name (in the markup)? Weld did this to some extent, it attempted to map the key's to the attributes of anything that matched the id. Am I understanding you correctly?

$(function() {

  var collection = [
    {id: 1, 'name': 'Louis CK'},
    {id: 2, 'name': 'Andy Kindler'},
    {id: 3, 'name': 'Greg Giraldo'}
  ];

  var html = "<a href='/users/ID'><span class='name'>NAME</span></a></br>";

  var map = Plates.Map();
  map.where('href').has(/ID/).insert('id');
  map.class('name').to('name');

  $('body').append(Plates.bind(html, collection, map));

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants