我正在尝试将Portlet从Liferay 6.1迁移到6.2并强制将Alloy代码调整为2.5版本和aui-pagination部分:
pagination = new A.Pagination({
circular: false,
containers: '.pagination',
on: {
changeRequest: function(event) {
var newState = event.state;
this.setState(newState);
}
},
total: 10,
});
但每当我从其他函数调用分页实例的changeRequest()时,我都会收到错误:
this._pagination.changeRequest();
有没有解决方案?
答案 0 :(得分:0)
你的问题有点奇怪。如果不在示例中传递changeRequest()
,您如何致电event
?为什么在事件已经自动发生的情况下设置状态?
要回答您提出的更通用的问题,有几种可能的解决方案以编程方式调用changeRequest()
函数:
定义一个命名函数并将其设置为changeRequest()
函数:
function changeRequest() {
console.log('changeRequest function called!');
}
var pagination = new Y.Pagination({ /* ...your code here... */ });
pagination.on('changeRequest', changeRequest);
// OR if you don't need to access the pagination component
// in your changeRequest() method
new Y.Pagination({
/* ...your code here... */
on: {
changeRequest: changeRequest
}
});
此方法仅在您不需要使用event
参数时,或者在实际事件发生时仅使用event
参数,或者构造{{1}时才有效参数你自己。
使用您的代码的可运行示例:
event

YUI().use('aui-pagination', function(Y) {
var pagination = new Y.Pagination({
circular: false,
containers: '.pagination',
total: 10,
});
function changeRequest(event) {
if (event) {
alert('changeRequest called with event');
var newState = event.state;
pagination.setState(newState);
} else {
alert('changeRequest called without event');
}
}
pagination.after('changeRequest', changeRequest);
pagination.render();
Y.one('#button').on('click', function() {
changeRequest();
});
});

致电pagination.next()
或pagination.prev()
:
<script src="http://cdn.alloyui.com/2.0.0/aui/aui-min.js"></script>
<link href="http://cdn.alloyui.com/2.0.0/aui-css/css/bootstrap.min.css" rel="stylesheet"></link>
<br />
<button id="button">call <code>changeRequest()</code></button>
使用您的代码的可运行示例:
YUI().use('aui-pagination', function(Y) {
// ...your code here...
pagination.next();
});
&#13;
YUI().use('aui-pagination', function(Y) {
var pagination = new Y.Pagination({
circular: false,
containers: '.pagination',
total: 10,
on: {
changeRequest: function(event) {
alert('changeRequest called with event');
var newState = event.state;
pagination.setState(newState);
}
}
}).render();
Y.one('#button').on('click', function() {
pagination.next();
});
});
&#13;
在其中一个 <script src="http://cdn.alloyui.com/2.0.0/aui/aui-min.js"></script>
<link href="http://cdn.alloyui.com/2.0.0/aui-css/css/bootstrap.min.css" rel="stylesheet"></link>
<br />
<button id="button">call <code>changeRequest()</code></button>
项目上模拟click
个事件:
pagination
使用您的代码的可运行示例:
YUI().use('aui-pagination', 'node-event-simulate', function(Y) {
// ...your code here...
pagination.getItem(1).simulate('click');
});
&#13;
YUI().use('aui-pagination', 'node-event-simulate', function(Y) {
var pagination = new Y.Pagination({
circular: false,
containers: '.pagination',
total: 10,
on: {
changeRequest: function(event) {
alert('changeRequest called with event');
var newState = event.state;
pagination.setState(newState);
}
}
}).render();
Y.one('#button').on('click', function() {
pagination.getItem(1).simulate('click');
});
});
&#13;