在 Framework7 Inside Pages 中传递 Url 中的变量
Pass Variables in Url in Framework7 Inside Pages
我是 Framework7.io 的新手。我有以下脚本,它根据 url 中传递的参数从 sqlite 中获取数据。
但是在index.html(F7第一页)调用了所有的J,而我在内页有get参数
b.html
中的代码
<a href="a.html?type=new&ok=fine" >Go to a with values of ok & type</a>
a.html
中的代码
function getParameterValue(type) {
type = type.replace(/[\[]/, "\[").replace(/[\]]/, "\]");
var regex = new RegExp("[\?&]" + type + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var type1 = getParameterValue('type');
更新:
目前正在使用此代码但没有成功。
$$(document).on('page:init', function (e) {
var page = e.detail.page;
myApp.alert(page);
if (page.name === 'a') {
var count = page.query.count;
myApp.alert(count);
// Now we can generate some dummy list
var listHTML = '<ul>';
for (var i = 0; i < count; i++) {
listHTML += '<li>' + i + '</li>';
}
listHTML += '</ul>';
// And insert generated list to page content
$$(page.container).find('.page-content').append(listHTML);
}
// Code for Services page
if (page.name === 'inch') {
myApp.alert('Here comes our inch!');
}
});
感谢您的宝贵时间,非常感谢您的帮助。
使用page.query.your_url_parameter
获取参数值。
示例:
获取<a href="a.html?type=new&ok=fine" >Go to a with values of ok & type</a>
参数:
$$(document).on('page:init', function (e) {
var page = e.detail.page;
if (page.name === 'a') {
var type = page.query.type; // returning "new"
var ok = page.query.ok; // returning "fine"
alert(type);
alert(ok);
}
// Code for Services page
if (page.name === 'inch') {
myApp.alert('Here comes our inch!');
}
});
我是 Framework7.io 的新手。我有以下脚本,它根据 url 中传递的参数从 sqlite 中获取数据。
但是在index.html(F7第一页)调用了所有的J,而我在内页有get参数
b.html
中的代码<a href="a.html?type=new&ok=fine" >Go to a with values of ok & type</a>
a.html
中的代码function getParameterValue(type) {
type = type.replace(/[\[]/, "\[").replace(/[\]]/, "\]");
var regex = new RegExp("[\?&]" + type + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var type1 = getParameterValue('type');
更新:
目前正在使用此代码但没有成功。
$$(document).on('page:init', function (e) {
var page = e.detail.page;
myApp.alert(page);
if (page.name === 'a') {
var count = page.query.count;
myApp.alert(count);
// Now we can generate some dummy list
var listHTML = '<ul>';
for (var i = 0; i < count; i++) {
listHTML += '<li>' + i + '</li>';
}
listHTML += '</ul>';
// And insert generated list to page content
$$(page.container).find('.page-content').append(listHTML);
}
// Code for Services page
if (page.name === 'inch') {
myApp.alert('Here comes our inch!');
}
});
感谢您的宝贵时间,非常感谢您的帮助。
使用page.query.your_url_parameter
获取参数值。
示例:
获取<a href="a.html?type=new&ok=fine" >Go to a with values of ok & type</a>
参数:
$$(document).on('page:init', function (e) {
var page = e.detail.page;
if (page.name === 'a') {
var type = page.query.type; // returning "new"
var ok = page.query.ok; // returning "fine"
alert(type);
alert(ok);
}
// Code for Services page
if (page.name === 'inch') {
myApp.alert('Here comes our inch!');
}
});