我有用户个人资料列表。我需要根据以下标准对用户配置文件进行排序,如下所示:
profile_claimed(boolean) -> profile_complete_status(integer) -> No_of_friends(integer)
Run Code Online (Sandbox Code Playgroud)
代码:
user_profiles.sort { |x| [x.claim ? 0 : 1, x.complete_profile_status, x.no_of_friends] }
Run Code Online (Sandbox Code Playgroud)
如何对用户配置文件进行排序?
我有一个包含一些客户相关信息的注册表。如果用户表单已填满一半并且用户将关闭选项卡,那么我将触发带有保存和退出选项的弹出窗口,退出。
我有一些 jQuery 解决方案。但是现在它不适用于所有浏览器。
Jquery 示例代码:
'use strict';
$(document).ready(function() {
$.fn.addEvent = function (obj, evType, fn) {
if (obj.addEventListener) {
obj.addEventListener(evType, fn, false);
return true;
} else if (obj.attachEvent) {
var r = obj.attachEvent('on'+evType, fn);
return r;
} else {
return false;
}
};
$.fn.KeepOnPage = function (e) {
var doWarn = 1;
if (!e) {
e = window.event;
}
if (!e) {
return;
}
if (doWarn == 1) { // and condition whatever you want to add here
e.cancelBubble …
Run Code Online (Sandbox Code Playgroud)