Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callback用不了? #18

Open
wodenwang opened this issue Jun 22, 2016 · 7 comments
Open

callback用不了? #18

wodenwang opened this issue Jun 22, 2016 · 7 comments

Comments

@wodenwang
Copy link

wodenwang commented Jun 22, 2016

<script>
    $(function () {

        var router = new Router({
            container: '#container',
            enterTimeout: 250,
            leaveTimeout: 250
        });

        var home = {
            url: '/',
            className: 'home',
            render: function () {
                return $('#home').html();
            }
        };

        var page = {
            url: '/page',
            className: 'page',
            render: function (callback) {
                Wxui.html('/c_Gavm3qM9X.view',function(html){
                    callback(null,html);
                });
            }
        };

        router.push(home)
            .push(page)
            .setDefault('/')
            .init();
    });
</script>

<div id="container">

</div>

<div id="home" style="display:none;">
<a href="#/page">第一页</a><p>首页</p>
</div>

Wxui.html是一个$.ajax的封转.

@wodenwang
Copy link
Author

报callback is not a function...

@progrape
Copy link
Owner

@wodenwang 请获取本仓库下最新的文件,https://github.com/progrape/router/blob/dev/dist/router.min.js

weui demo 页面的文件是旧版本的

@wodenwang
Copy link
Author

@progrape thx.

@wodenwang
Copy link
Author

@progrape 十分抱歉,又是我.

callback需要两个入参,第一个入参表示什么?有没有更详细点的示例用法?

@progrape
Copy link
Owner

render: function (callback){
        callback(null, '<button>home</button>');
}

callback 的第一个参数约定是标识错误,如果没有错误就传入 null ,第二个参数就是 html 字符串

@wodenwang
Copy link
Author

嗯.假如我希望标识错误,是传入什么内容呢?

@progrape
Copy link
Owner

progrape commented Jul 1, 2016

@wodenwang 可以传入一个 new Error('') 对象

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants