arturadib / agility

Javascript MVC for the "write less, do more" programmer
http://agilityjs.com
MIT License
542 stars 70 forks source link

complex attributes data-bind #74

Open thalisvilela opened 12 years ago

thalisvilela commented 12 years ago

My problem is:

With this:

obj = $$({ model:{ attr:{ subAttr:"some stuff" } }, view:{ format:"someElement data-bind="attr.subAttr" " })

output this: someElement> some stuff </someElement

thalisvilela commented 12 years ago

And also with some custom attributes like:

obj = $$({ model:{}, customAttribute:{ subAttrSet:{ key:value } } })

phonovision commented 12 years ago

As a workaround you could flatten the object into the model:

var test = $$({
    attr : {first:'abc', second:'def', third:'this is not used'}
  }, '<div>The first: "<span data-bind="first"/>" and the second: "<span data-bind="second"/>"</div>', {
    'create' : function() {
      var attr = this.model.get('attr');
//attr is nulled to free unused elements of the object
      this.model.set({first:attr.first, second:attr.second, attr:null});
    }
  });

This will output: The first: "abc" and the second: "def"