zoukankan      html  css  js  c++  java
  • Step 21: Data Types

    Step 21: Data Types

    https://ui5.sap.com/#/topic/dfe04650afc046e0802abb1a1a90d2d9

    上一节的json文件里只有价格,但是没有币种,UI5通过使用Data Types,可以根据币种的不同,自动格式化价格数字,
    比如虽然价格的数字是一样的,但是日元和美元的表示格式是不同的。

    webapp/view/InvoiceList.view.xml

    <mvc:View
       controllerName="sap.ui.demo.walkthrough.controller.InvoiceList"
       xmlns="sap.m"
       xmlns:mvc="sap.ui.core.mvc">
       <List
          headerText="{i18n>invoiceListTitle}"
          class="sapUiResponsiveMargin"
          width="auto"
          items="{invoice>/Invoices}">
          <items>
             <ObjectListItem
    		title="{invoice>Quantity} x {invoice>ProductName}"
    		number="{
    			parts: [{path: 'invoice>ExtendedPrice'}, {path: 'view>/currency'}],
    			type: 'sap.ui.model.type.Currency',
    			formatOptions: {
    				showMeasure: false
    			}
    		}"
    		numberUnit="{view>/currency}"/>
    	</items>
       </List>
    </mvc:View>
    

    1,追加了controller
    2,number and numberUnit属性:在每一个条目的右侧显示价格和币种
    3,type属性,通过币种的data type的不同,格式化数字
    4,在number属性上使用了特殊的binding syntax 。这种绑定语法利用了所谓的“计算字段”,它允许将来自不同模型的多个属性绑定到控件的单个属性。parts代表多个model,这里用了2个model,一个是invoice>ExtendedPrice,一个是view>/currency.
    5,Currency type是根据币种的不同,格式化数字。由于Invoices.json文件里没有币种,所以加了一个controller,负责返回币种。
    6,numberUnit属性,在价格的下面显示币种。
    7,showMeasure属性,如果是true的话,则在价格后面显示币种,因为加了numberUnit属性,所以这里设置成false就可以,或者整体不要formatOptions属性。

    webapp/controller/InvoiceList.controller.js (New)

    sap.ui.define([
    	"sap/ui/core/mvc/Controller",
    	"sap/ui/model/json/JSONModel"
    ], function (Controller, JSONModel) {
    	"use strict";
    
    	return Controller.extend("sap.ui.demo.walkthrough.controller.InvoiceList", {
    
    		onInit : function () {
    			var oViewModel = new JSONModel({
    				currency: "EUR"
    			});
    			this.getView().setModel(oViewModel, "view");
    		}
    
    	});
    });
    

    约定:尽可能使用Data Types,不要使用自定义的格式化数字的程序。

    vx:xiaoshitou5854

  • 相关阅读:
    EF数据库初始化策略及种子数据的添加
    Win10 FaceAPI小demo开发问题汇总
    本地Git服务器的搭建及使用
    JSP利用freemarker生成基于word模板的word文档
    Mvc项目架构分享之项目扩展
    mvc项目架构搭建之UI层的搭建
    mvc项目架构分享系列之架构搭建之Repository和Service
    mvc项目架构分享系列之架构搭建之Infrastructure
    mvc项目架构分享系列之架构搭建初步
    [svc]HTTPS证书生成原理和部署细节
  • 原文地址:https://www.cnblogs.com/xiaoshiwang/p/15232216.html
Copyright © 2011-2022 走看看