bingo 跨action异步获取参数

时间:2021-04-01 16:23:22

html(定时器模拟异步)

<script>
setTimeout(function(){
window.teacInfo = {a:1,b:2};
},2000);
</script>

service

bingo.service('commonSrv', function ($view, $var) {
if($view.commonSrv) return $view.commonSrv;
return {
teacInfo: function (func) {
var teacInfoTimer = setInterval(function(){
if(!window.teacInfo) return false;
clearInterval(teacInfoTimer);
teacInfoTimer = null;
func();
},10);
} } });

action

bingo.using('service/commonSrv');
bingo.action('classInfo/index', function ($view,commonSrv) {

    commonSrv.teacInfo(function(){
console.log(window.teacInfo);
}); });