This repository has been archived on 2023-08-29. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
anot.js
Archived
1
0
Fork 0
anot.js/src/19-:data.js

20 lines
478 B
JavaScript
Raw Permalink Normal View History

2018-08-04 16:26:50 +08:00
//兼容2种写法 :data-xx="yy", :data="{xx: yy}"
Anot.directive('data', {
priority: 100,
init: directives.attr.init,
update: function(val) {
var obj = val
if (typeof obj === 'object' && obj !== null) {
if (!Anot.isPlainObject(obj)) obj = val.$model
for (var i in obj) {
this.element.setAttribute('data-' + i, obj[i])
}
} else {
if (!this.param) return
this.element.setAttribute('data-' + this.param, obj)
}
}
})