forked from fanruan/fineui
Browse Source
Merge in VISUAL/fineui from ~GUY/fineui:master to master * commit '1dd49715d4039eabc66e8a86167761ec3100f1ae': 优化一下context的传递 优化一下context的传递 Revert "优化一下context的传递" 优化一下context的传递 优化一下context的传递 优化一下context的传递es6
guy
4 years ago
7 changed files with 130 additions and 53 deletions
@ -0,0 +1,118 @@
|
||||
<html> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title></title> |
||||
<link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.css"/> |
||||
<script src="../dist/2.0/fineui.js"></script> |
||||
</head> |
||||
<body> |
||||
<div id="wrapper"></div> |
||||
<script> |
||||
// tab上下文环境测试 |
||||
var Model = BI.inherit(Fix.Model, { |
||||
state: function () { |
||||
return { |
||||
expand: false |
||||
}; |
||||
}, |
||||
childContext: ["text"], |
||||
|
||||
computed: { |
||||
text: function () { |
||||
return this.model.expand ? "text-yes" : "text-not"; |
||||
} |
||||
}, |
||||
|
||||
actions: { |
||||
toggle: function () { |
||||
this.model.expand = !this.model.expand; |
||||
} |
||||
} |
||||
}); |
||||
|
||||
BI.model("demo.model", Model); |
||||
var ChildModel = BI.inherit(Fix.Model, { |
||||
context: ["text"] |
||||
}); |
||||
|
||||
BI.model("demo.child_model", ChildModel); |
||||
|
||||
var Child = BI.inherit(BI.Widget, { |
||||
setup: function () { |
||||
var store = BI.useStore(function () { |
||||
return BI.Models.getModel("demo.child_model"); |
||||
}); |
||||
return { |
||||
render: function () { |
||||
return { |
||||
type: "bi.label", |
||||
text: store.model.text |
||||
}; |
||||
} |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.child", Child); |
||||
|
||||
var Widget = BI.inherit(BI.Widget, { |
||||
props: { |
||||
updateMode: "auto" |
||||
}, |
||||
setup: function () { |
||||
var child; |
||||
var store = BI.useStore(function () { |
||||
return BI.Models.getModel("demo.model"); |
||||
}); |
||||
setInterval(function () { |
||||
store.toggle(); |
||||
}, 1000); |
||||
BI.watch("text", function () { |
||||
// child.reset(); |
||||
}); |
||||
return function () { |
||||
return { |
||||
type: "bi.vertical", |
||||
vgap: 20, |
||||
items: [{ |
||||
type: "demo.child", |
||||
ref: function (_ref) { |
||||
child = _ref; |
||||
} |
||||
}, { |
||||
type: "bi.combo", |
||||
el: { |
||||
type: "bi.button", |
||||
text: "点击" |
||||
}, |
||||
popup: { |
||||
el: { |
||||
type: "bi.tab", |
||||
height: 100, |
||||
showIndex: 0, |
||||
cardCreator: function () { |
||||
return { |
||||
type: "demo.child" |
||||
}; |
||||
} |
||||
} |
||||
} |
||||
}] |
||||
}; |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.parent", Widget); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
items: [{ |
||||
el: { |
||||
type: "demo.parent" |
||||
}, |
||||
top: 100, |
||||
left: 100 |
||||
}], |
||||
element: "#wrapper" |
||||
}); |
||||
</script> |
||||
</body> |
||||
</html> |
Loading…
Reference in new issue