Skip to content

Commit

Permalink
feat:支持bind部分功能 (#891)
Browse files Browse the repository at this point in the history
* feat:支持bind部分功能

* 修改dom变量

* 修改dom变量
  • Loading branch information
wupengFEX authored and schoeu committed Nov 10, 2017
1 parent 6ee340a commit 3ac7a09
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/mip-bind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ mip-bind 数据驱动组件,可以允许开发者在页面中动态操作数
}
</script>
</mip-data>
<div on="tap:MIP.setstate({age: 25})"></div>
<div m-text="name"></div>
<mip-data src="https://www.example.com"></mip-data>
<div on="tap:MIP.setData({age:25}) swip:MIP.setData({name:'Jack'})"></div>
```

## 属性

## 注意事项
其中 mip-data 为绑定数据的组件,属性如下:

### src
用于通过异步请求获取数据
20 changes: 12 additions & 8 deletions src/mip-bind/mip-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,27 @@ define(function (require) {
this._compile = new Compile();
this._observer = new Observer();
this._bindEvent();
MIP.setData = function (data) {
me._bindTarget(false, data);
// from=0 called by html attributes
// from=1 refers the method called by mip.js
MIP.setData = function (action, from) {
me._bindTarget(false, action, from);
};
MIP.$set = function (data) {
me._bindTarget(true, data);
MIP.$set = function (action, from) {
me._bindTarget(true, action, from);
}
};

/**
* Bind target
*
*/
Bind.prototype._bindTarget = function (compile, data) {
if (typeof data === "string") {
data = (new Function('return ' + data))();
Bind.prototype._bindTarget = function (compile, action, from) {
var data = from ? action.arg : action;
var evt = from ? action.event.target: {};
if (typeof data === 'string') {
data = (new Function('DOM', 'return ' + data))(evt);
}
if (typeof data === "object") {
if (typeof data === 'object') {
fn.extend(window.m, data);
if (compile) {
this._observer.start(this._win.m);
Expand Down
1 change: 0 additions & 1 deletion src/mip-bind/mip-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ define(function (require) {
node.removeAttribute(attrName);
}
catch (e) {
console.warn(e);
}
return value;
};
Expand Down
1 change: 0 additions & 1 deletion src/mip-bind/mip-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ define(function (require) {
+ 'try {'
+ 'return ' + exp
+ '} catch (e) {'
+ 'console.warn(e)'
+ '}'
+ '}'
));
Expand Down

0 comments on commit 3ac7a09

Please sign in to comment.