为了账号安全,请及时绑定邮箱和手机立即绑定

下面的代码如何优化一下

下面的代码如何优化一下

qq_小树_6 2017-11-05 18:10:21
 var moduleModel = new Bb.Model({});                         var data1 = _.find(m.get('data'), function(d) {                             return d.elementCode == 'usagetype'                         });                         var data2 = _.find(m.get('data'), function(d) {                             return d.elementCode == 'policystatus'                         });                         var data3 = _.find(m.get('data'), function(d) {                             return d.elementCode == 'riskname'                         });                         var data4 = _.find(m.get('data'), function(d) {                             return d.elementCode == 'businessnature'                         });                         var data5 = _.find(m.get('data'), function(d) {                             return d.elementCode == 'chnltype'                         });                         var data6 = _.find(m.get('data'), function(d) {                             return d.elementCode == 'paymethod'                         });                         var data7 = _.find(m.get('data'), function(d) {                             return d.elementCode == 'traveltaxmark'                         });                         if (data1.dataList && data2.dataList && data3.dataList && data4.dataList && data5.dataList && data6.dataList && data7.dataList) {                             moduleModel.set('usagetype', data1.dataList);                             moduleModel.set('policystatus', data2.dataList);                             moduleModel.set('riskname', data3.dataList);                             moduleModel.set('businessnature', data4.dataList);                             moduleModel.set('chnltype', data5.dataList);                             moduleModel.set('paymethod', data6.dataList);                             moduleModel.set('traveltaxmark', data7.dataList);                             that.showChildView('policystatus', new policystatusView({                                 model: moduleModel,                                 el: that.getUI('policystatus')                             }));                             that.getChildView('policystatus').render();                             that.showChildView('businessnature', new businessnatureView({                                 model: moduleModel,                                 el: that.getUI('businessnature')                             }));                             that.getChildView('businessnature').render();                             that.showChildView('chnltype', new chnltypeView({                                 model: moduleModel,                                 el: that.getUI('chnltype')                             }));                             that.getChildView('chnltype').render();                             that.showChildView('traveltaxmark', new traveltaxmarkView({                                 model: moduleModel,                                 el: that.getUI('traveltaxmark')                             }));                             that.getChildView('traveltaxmark').render();                             that.showChildView('paymethod', new paymethodView({                                 model: moduleModel,                                 el: that.getUI('paymethod')                             }));                             that.getChildView('paymethod').render();                             that.showChildView('usagetype', new usagetypeView({                                 model: moduleModel,                                 el: that.getUI('usagetype')                             }));                             that.getChildView('usagetype').render();                             that.showChildView('riskname', new risknameView({                                 model: moduleModel,                                 el: that.getUI('riskname')                             }));                             that.getChildView('riskname').render();                         } else {                             layer.alert('查询失败!');                             return false;                         }                     },                     error: function(e) {                         layer.close(idx);                         if (e.responseText === 'logout') {                             window.location.href = '/login.html';                         }                         layer.alert('请求失败!');                     }
查看完整描述

1 回答

已采纳
?
习惯受伤

TA贡献885条经验 获得超1144个赞

用循环搞定,你看重复的语句很多的。现在在手机上,完了有时间上电脑给你代码

查看完整回答
2 反对 回复 2017-11-08
  • 1 回答
  • 0 关注
  • 1243 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信