官术网_书友最值得收藏!

Passing in a second variable

The alternative to the preceding autodetection is to pass the second variable into the format function. This gives us greater flexibility and scalability should we wish to format other fields. With the second variable, we can either pass in a fixed string that matches a preselected list in our switch statement or we could pass in the field itself. An example of the fixed string approach in the view would be:

      {{ format(person.balance, 'currency') }}

This would work perfectly and would be great if we had several different fields that all needed to be formatted like balance currently does, but there seems to be some slight repetition in using the balance key and currency format. 

As a compromise, we are going to pass the person object as the first parameter, so we can access all the data, and the name of the field as the second parameter. We will then use this for both identifying the format method required and to return the specific data.

主站蜘蛛池模板: 肥西县| 松滋市| 乌恰县| 龙江县| 上饶市| 常山县| 辽源市| 锡林浩特市| 蒙城县| 靖宇县| 旬邑县| 容城县| 安龙县| 汉川市| 望奎县| 建水县| 顺昌县| 延川县| 汕尾市| 泗阳县| 康马县| 庆安县| 东至县| 永兴县| 榆社县| 治县。| 晋江市| 蓬溪县| 运城市| 丰台区| 乐安县| 峨眉山市| 忻城县| 连平县| 巨野县| 碌曲县| 和田县| 邯郸县| 乌海市| 阳城县| 吉林省|