router icon indicating copy to clipboard operation
router copied to clipboard

callback用不了?

Open wodenwang opened this issue 9 years ago • 7 comments

<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 avatar Jun 22 '16 09:06 wodenwang

报callback is not a function...

wodenwang avatar Jun 22 '16 09:06 wodenwang

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

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

progrape avatar Jun 22 '16 09:06 progrape

@progrape thx.

wodenwang avatar Jun 22 '16 09:06 wodenwang

@progrape 十分抱歉,又是我.

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

wodenwang avatar Jun 22 '16 09:06 wodenwang

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

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

progrape avatar Jun 23 '16 03:06 progrape

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

wodenwang avatar Jun 24 '16 02:06 wodenwang

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

progrape avatar Jul 01 '16 03:07 progrape