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

我希望在一个页面render之前请求一下数据 #17

Open
xhacker5000 opened this issue Jun 3, 2016 · 3 comments
Open

我希望在一个页面render之前请求一下数据 #17

xhacker5000 opened this issue Jun 3, 2016 · 3 comments

Comments

@xhacker5000
Copy link

是不是可以写成这样

// button
    var button = {
        url: '/button',
        className: 'button',
        render: function () {

            //do something query
            xxxx.query();
            return $('#tpl_button').html();
        }
    };
@cgfeel
Copy link

cgfeel commented Jun 5, 2016

同求

@zouzhenxing
Copy link

var button = {
        url: '/button',
        className: 'button',
        render: function () {
            //使用JQuery deferred对象
            var d = $.Deferred();
            $.ajax(...).done(function( data ){
                   var html = ejs.render($('#tpl_button').html(),{data:data});
                   d.resolve(html);
            });
            return d.promise();
        }
 };

@zouzhenxing
Copy link

zouzhenxing commented Aug 24, 2016

var button = {
        url: '/button',
        className: 'button',
        render: function () {
            return $.ajax(...).done(function( data ){
                   return ejs.render($('#tpl_button').html(),{data:data});
            });
        }
 };

似乎这样会更简洁

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

3 participants