WXS
WXS( )是小程序的一套腳本語言,結(jié)合 WXML,可以構(gòu)建出頁面的結(jié)構(gòu)。
注意事項 WXS 不依賴于運(yùn)行時的基礎(chǔ)庫版本微信小程序技術(shù)文檔,可以在所有版本的小程序中運(yùn)行。 WXS 與 是不同的語言,有自己的語法,并不和 一致。 WXS 的運(yùn)行環(huán)境和其他 代碼是隔離的微信小程序技術(shù)文檔,WXS 中不能調(diào)用其他 文件中定義的函數(shù),也不能調(diào)用小程序提供的API。 WXS 函數(shù)不能作為組件的事件回調(diào)。 由于運(yùn)行環(huán)境的差異,在 iOS 設(shè)備上小程序內(nèi)的 WXS 會比 代碼快 2 ~ 20 倍。在 設(shè)備上二者運(yùn)行效率無差異。
以下是一些使用 WXS 的簡單示例,要完整了解 WXS 語法,請參考WXS 語法參考。
頁面渲染
<wxs module="m1">
var msg = "hello world";

module.exports.message = msg;
wxs>
<view> {{m1.message}} view>
頁面輸出:
hello world

數(shù)據(jù)處理
// page.js
Page({
data: {
array: [1, 2, 3, 4, 5, 1, 2, 3, 4]
}
})

<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>

<view> {{m1.getMax(array)}} view>
頁面輸出:
5
The are by and are for only. In case of any and the and the , the shall . .