party_bid竞价报名总结

1.模拟发短信

在sms.js中:

var native_accessor = {
    send_sms: function (phone, message) {
        native_access.send_sms({"receivers": [
            {"name": 'name', "phone": phone}
        ]}, {"message_content": message});
    },
    receive_message: function (json_message) {
        if (typeof this.process_received_message == 'function') {
            this.process_received_message(json_message);
        }
    },

    process_received_message: function (json_message) {
        
    }
};

function notify_message_received(message_json) {
    native_accessor.receive_message(message_json);
};

 在console中:notify_message_received({"messages": [ {"create_date": "Tue Jan 15 15:28:44 格林尼治标准时间+0800 2013", "message": "bm1", "phone": "181717833"} ]})

 

2.处理短信:
①去空格:

var message = json_message.messages[0].message.replace(/\s/g, "");

 ②判断是否以bm开头:

全部转化为大写判断keyword:

var message_keywordjson_message.messages[0].message.substr(0,2).toUpperCase();

 从短信内容第零个字符串开始,取两个字符转换为大写字母,作为关键字

3.  在正则表达式中:

\s: space, 空格
+: 一个或多个
^: 开始,^\s,以空格开始
$: 结束,\s$,以空格结束
|:或者
/g:global, 全局
replace() 替换

i:不区分大

 

4.   console.log(需要打印的代码,'标志')

用来检测写的代码是否执行.可用来模拟恢复短信:

console.log('恭喜!报名成功'); 

 

5.  正在报名的活动对应的活动列表的颜色为黄色,可用class的命名来解决 .在显示活动列表haml中绑定

class="{{activity.status}}"  

activity的status可以有start,unStart,end.在index.css中写样式:

 

.start{  
    background: yellow !important
}

//一定要注意!important,可能原来的css中就有颜色控制,这时候如不加此句,则颜色可能会显示不出来 

 

在index.haml中引入此样式:

%link(rel="stylesheet" type="test/css" href="/css/index.css")

6.  当接收到一条报名短信并判断符合格式,将信息保存到本地之后,需要在报名页面立刻更新出报名者的信息

 

在需要刷新的页面的haml中设置id:

#sign_up_page_id.ng-scope

 在sms.js中定义一个刷新的函数,刷新要迭代的数组信息:

function sign_up_page_refresh() {
    var refresh_page = document.getElementById('sign_up_page_id')
    if (refresh_page) {
        var scope = angular.element(refresh_page).scope();
        scope.$apply(function () {
            scope.get_apply_peoples();
        })
    }
};

 并在接受到短信后调用相应js中的函数:

 

 $scope.get_apply_peoples = function () {
        var activity_names = JSON.parse(localStorage.getItem('activity_names'));
        var activity = _.find(activity_names, function (activity) {
            return activity.name == localStorage.current_signing_up_page_name;
        })
        if (activity != undefined) {
            $scope.apply_peoples = activity.apply_people;
            $scope.counter = activity.apply_people.length + '人';
        }
}

 

7.  _.find

在list中逐项查找,返回第一个通过predicate迭代函数真值检测的元素值,如果没有传递给迭代器将返回underfind。如果找到匹配的元素,函数将立刻返回,不会遍历整个list。

function get_current_activity_bid() {
    var current_activity_bids = get_current_activity_bids();
    return  _.find(current_activity_bids, function (bid) {
        return bid.bid_name == localStorage.getItem('current_bid_sign_up_page_name');
    })
};

 

8.  _filter

 

遍历list中的每个值,返回包含所有通过predicate真值检测的元素值。

 

function get_current_activity_bids() {
    var bids = JSON.parse(localStorage.getItem('bids')) || [];
    var current_activity_bids = null;
    current_activity_bids = _.filter(bids, function (bid) {
        return bid.active_name == localStorage.current_signing_up_page_name;
    })
    return current_activity_bids;
};

 

9.  _.map

通过变换函数(iterator迭代器)把list中的每个值映射到一个新的数组(产生一个新的数组)。

function save_apply_people(apply_people) {
    var current_activity = get_activity();
    var activities = JSON.parse(localStorage.getItem('activity_names'));
    _.map(activities, function (activity) {
        if (activity.name == current_activity.name) {
            activity.apply_people = apply_people;
        }
    })
    localStorage.setItem("activity_names", JSON.stringify(activities));
    sign_up_page_refresh();
};

 具体关于underscore内容看http://www.css88.com/doc/underscore/

 

 

猜你喜欢

转载自kangxiaoya.iteye.com/blog/2054284