Created
May 17, 2018 07:49
-
-
Save zhangkn/f8d955588bb92d5ac489dc7fbd59d3c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--wxml--> | |
<!-- 下面的 getMax 函数,接受一个数组,且返回数组中最大的元素的值 --> | |
<wxs module="m1"> | |
var getMax = function(array) { | |
var max = undefined; | |
for (var i = 0; i < array.length; ++i) { | |
max = max === undefined ? | |
array[i] : | |
(max >= array[i] ? max : array[i]); | |
} | |
return max; | |
} | |
module.exports.getMax = getMax; | |
</wxs> | |
<!-- 调用 wxs 里面的 getMax 函数,参数为 page.js 里面的 array --> | |
<view> {{m1.getMax(array)}} </view> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// page.js | |
Page({ | |
data: { | |
array: [1, 2, 3, 4, 5, 1, 2, 3, 4] | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment