(function (app, _) {
// 工具
function Util() { }
Util.prototype.goTo = function (url, extras) {
var kvs = _.map(extras, function (val, key) {
return _.sprintf('%s=%s', key, val);
});
kvs.push('t=' + new Date().getTime());
var search = kvs.join('&');
location.href = url + '?' + search;
};
Util.prototype.getExtrasValue = function (key) {
var extras = this.getExtras();
if (!extras) return undefined;
if (key in extras) {
return extras[key];
}
return undefined;
}
Util.prototype.getExtras = function () {
if (!this.requestParam && location.search) {
var self = this;
self.requestParam = {};
var items = location.search.substring(1).split('&');
$(items).each(function () {
var arr = this.split('=');
self.requestParam[arr[0]] = arr[1];
});
}
return this.requestParam;
}
})(app, _);
_.为underscore.js的方法
goTo 方法为跳转方法,url为跳转链接,extras为传递参数,格式为obj
getExtrasValue 方法获取指定参数
getExtras 方法获取所有参数