美文网首页
JSPatch下发笔记1

JSPatch下发笔记1

作者: anny_4243 | 来源:发表于2016-12-20 18:30 被阅读19次

    原代码

    @implementation CommunityViewController
    - (void)jump:(UIButton *)sender{
        CommunityBannerModel *model = _arr[sender.tag];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setValue:model.action_type forKey:@"type"];
        [dict setValue:model.url forKey:@"value"];
        [[PushJumpManager sharedInstance]pushActionWithModel:dict];
    }
    @end
    

    JS代码

    require('NSMutableDictionary,PushJumpManager');
    defineClass('CommunityViewController', {
                jump: function(sender) {
                var i = sender.tag();
                var model = self.valueForKey("_arr").objectAtIndex(i);
                console.log(model);
                var dict = NSMutableDictionary.dictionary();
                console.log(dict);
                dict.setValue_forKey(model.valueForKey("action_type"), "type");
                console.log(model.valueForKey("action_type"));
                dict.setValue_forKey(model.valueForKey("url"), "value");
                console.log(model.valueForKey("action_type"));
                console.log(dict);
                PushJumpManager.sharedInstance().pushActionWithModel(dict);
                },
                });
    

    注意:
    1.把需要用到的类写在require方法里,相当于引用。
    2.实例变量的写法。
    _arr 写成 self.valueForKey("_arr")
    3.数组下标的写法。
    arr[i]写成arr.objectAtIndex(i)
    4.jsonModel值的写法。
    model.url写成model.valueForKey("url")
    5.在调试的时候把需要打印的值用console.log()方法输出到控制台方便调试。

    相关文章

      网友评论

          本文标题:JSPatch下发笔记1

          本文链接:https://www.haomeiwen.com/subject/xolfvttx.html