无法获得对象属性的值

时间:2014-11-15 13:51:52

标签: javascript jquery

不确定这里发生了什么。我有一个函数,它是WordPress插件的事件处理程序:

$.fn.almComplete = function(alm){
    console.log(alm);
    console.log(alm.finished);
}

第一个输出是:

e.ajaxloadmore {AjaxLoadMore: Object, page: 0, speed: 300, proceed: false, init: false…}
AjaxLoadMore: Object
button: m.fn.init[1]
button_label: "Load More"
content: m.fn.init[1]
data: m.fn.init[2]
el: m.fn.init[1]
finished: true
init: false
lang: ""
loading: false
max_pages: 5
offset: 0
page: 0
pause: false
post_type: Array[1]
posts_per_page: 6
prefix: "alm-"
proceed: true
repeater: "default"
scroll: false
speed: 300
transition: "slide"
window: m.fn.init[1]
__proto__: Object

但第二个输出console.log(alm.finished)始终输出false,但该属性显然不是假的,因此我不相信我正确引用此变量。

如何访问alm对象的属性?

编辑:这是在插件代码中调用此回调的时候:

        success: function (data) {
           alm.data = $(data); // Convert data to an object
           //console.log(alm.data.length);
           if (alm.init) {
              alm.button.text(alm.button_label);
              alm.init = false;
           }
           if (alm.data.length > 0) {
              alm.el = $('<div class="' + alm.prefix + 'reveal"/>');
              alm.el.append(alm.data);
              alm.el.hide();
              alm.content.append(alm.el);
              if (alm.transition === 'fade') { // Fade transition
                 alm.el.fadeIn(alm.speed, 'alm_easeInOutQuad', function () {
                    alm.loading = false;
                    alm.button.delay(alm.speed).removeClass('loading');
                    if (alm.data.length < alm.posts_per_page) {
                       alm.finished = true;
                       alm.button.addClass('done');
                    }
                 });
              } else { // Slide transition
                 alm.el.slideDown(alm.speed, 'alm_easeInOutQuad', function () {
                    alm.loading = false;
                    alm.button.delay(alm.speed).removeClass('loading');
                    if (alm.data.length < alm.posts_per_page) {
                       alm.finished = true;
                       alm.button.addClass('done');
                    }
                 });
              }

              if ($.isFunction($.fn.almComplete)) {
                 $.fn.almComplete(alm);
              }

           } else {
              alm.button.delay(alm.speed).removeClass('loading').addClass('done');
              alm.loading = false;
              alm.finished = true;
           }
        },

此外,完整的js源代码位于:https://github.com/dcooney/wordpress-ajax-load-more/blob/master/ajax-load-more/core/js/ajax-load-more.js

0 个答案:

没有答案