gpt4 book ai didi

jquery-mobile - jQueryMobile : Uncaught TypeError: Cannot call method '_trigger' of undefined

转载 作者:行者123 更新时间:2023-12-04 12:10:22 25 4
gpt4 key购买 nike

我正在使用带有backbone.js 的jQuery Mobile。当我加载主页时,出现以下错误:

Uncaught TypeError: Cannot call method '_trigger' of undefined 

这就是我加载主页的方法。
在routes.js中:
routes:{
'':'home',
}
home:function () {
new HomeView();
this.changePage(new HomeContentView());
},
changePage:function (page) {
$(page.el).attr('data-role', 'page');
console.log($(page.el));
page.render();
$('body').append($(page.el));
var transition = $.mobile.defaultPageTransition;
if (this.firstPage) {
transition = 'none';
this.firstPage = false;
}
$.mobile.changePage($(page.el), {changeHash:false, transition: transition});
}

在 view.js
window.HomeView = Backbone.View.extend({
template : Handlebars.compile($('#home').html()),
render : function (eventname) {
this.$el.html(this.template());
this.header = new HeaderElement();
this.$el.find('div.header_element').append(this.header.$el);
this.footer = new FooterElement();
this.$el.find('div.footer_element').append(this.footer.$el);
return this;
}
});


window.HomeContentView = Backbone.View.extend({
initialize: function(options) {
this.collection = new Fan();
this.template = Handlebars.compile(tpl.get('elements/home'));
//~ console.log(tpl.get('home'));
this.collection.on("reset",this.render,this);
this.init = true;

if (this.init) {
upLimit = 1;
this.collection.index();
this.init = false;
}
},
el: '#home_content_view',
render : function (eventName) {
var self = this;
var js = (self.collection.toJSON())[0];
console.log(js);

$('#home_content_view').html(self.template(js));
$('#home_content_view').trigger("create");
}
});

在 home.html
<div data-role="content">
hi
</div>

错误堆栈跟踪:
  Uncaught TypeError: Cannot call method '_trigger' of undefined jquery.mobile-1.1.1.js:2843
transitionPages jquery.mobile-1.1.1.js:2843
$.mobile.changePage jquery.mobile-1.1.1.js:3465
Backbone.Router.extend.changePage routes.js:153
Backbone.Router.extend.home routes.js:37
f.extend.route backbone-min.js:27
f.extend.loadUrl backbone-min.js:32
b.some.b.any underscore-min.js:14
f.extend.loadUrl backbone-min.js:32
f.extend.start backbone-min.js:31
(anonymous function) routes.js:162
$.ajax.success view.js:29
v.Callbacks.l jquery-1.8.3.min.js:2
v.Callbacks.c.fireWith jquery-1.8.3.min.js:2
T jquery-1.8.3.min.js:2
v.support.ajax.v.ajaxTransport.send.r jquery-1.8.3.min.js:2

其他页面正确呈现。只有主页给我带来了麻烦。
我哪里出错了?我该如何解决这个问题?

最佳答案

我认为这个错误可能是因为 jQuery Mobile 需要一个适当的元素来过渡到 changePage .这是一个黑客,但放置一个空 divdata-role在 index.html 中设置为 'page' 的属性应该可以解决它:

<body>
<!-- jQM seems to need a page to exist in the document before it transitions to the first dynamically generated one -->
<div data-role="page"></div>
</body>

关于jquery-mobile - jQueryMobile : Uncaught TypeError: Cannot call method '_trigger' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13838056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com