微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery mobile骨干:在初始化之前不能在listview上调用方法

我只是试图结合骨干js和 jquery手机的优势.我正在为移动设备开发,目前正在尝试开发动态列表,用于调试日志消息.想象你有一个控制台窗口,想把条目放在里面.事情是,总是插入一个新的>,列表必须刷新ala’$(‘#myList’).listview(‘refresh’).这不适合我,我得到错误

错误:在初始化之前不能在listview上调用方法;尝试调用方法’刷新’

tagName:’ul’,
id:’console’,

consoleTemplate : _.template($('#console-template').html()),initialize : function() {
        console.log('ConsoleView:init');            

        this.$el.attr('data-inset','true');
        this.$el.attr('data-role','listview');
        this.$el.css('width','50%');
        this.$el.append(this.consoleTemplate());

        // für alle Funktionen die mit this arbeiten
        _.bindAll(this,'render','addConsoleItem','appendConsoleItem');

        this.consoleItemCollection = new ConsoleItemCollection();
        this.consoleItemCollection.bind('add',this.appendConsoleItem);

        this.counter = 0;
        this.render();

    },render : function() {
        console.log('ConsoleView:render');

        var self = this;

        _(this.consoleItemCollection.models).each(function(item) {
            self.addConsoleItem(item);
        },this);

        return this;
    },

^^这是我的控制台视图的提取.

var view = Backbone.View.extend({

    el : 'div',id : 'content',consoleView : null,initialize : function() {
        console.log('ApplicationView:init');

        _.bindAll(this,'render');

        this.$el.attr('data-role','content');

        _.bindAll(this,'render');
        this.consoleView = new ConsoleView();
        this.consoleView.addConsoleItem(new ConsoleItemmodel());

    },render : function() {
        console.log('ApplicationView:render');

        this.$el.append(this.consoleView.render().el);

        return this;
    }

});

这是我的应用程序视图.

那么调用刷新方法

谢谢!

解决方法

jQuery Mobile listview需要在刷新之前进行初始化才能被触发:
$('#myList').listview().listview('refresh');

如果您想了解更多信息,为什么在使用jQuery Mobile中动态创建的内容时要小心,请查看我的博客ARTICLE.或者您可以找到它HERE.

原文地址:https://www.jb51.cc/jquery/176456.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐