Sapui5 在 xml 中使用我的新控件

Sapui5 use my new controle in xml

这是我创建新控件的方式:

https://sapui5.hana.ondemand.com/sdk/#docs/guide/91f0a8dc6f4d1014b6dd926db0e91070.html

sap.ui.somelib.SomeControl.extend("my.OwnControl", {
       ...
       init: function() {
             if (sap.ui.somelib.SomeControl.prototype.init) { // check whether superclass implements the method
                    sap.ui.somelib.SomeControl.prototype.init.apply(this, arguments); // call the method with the original arguments
             }

             //... do any further initialization of your subclass... 
       } 

可以在我的 xml 视图中使用一些控件吗?

像这样定义控件时: sap.ui.core.Control.extend("my.Square", ...

并声明 XML 命名空间 xmlns:my="my"

您可以像这样使用您的控件: <my:Square text="test" size="100px"/>

但前提是您还将控件声明为现有模块: jQuery.sap.declare("my.Square"); (另一个答案中缺少最后一部分)

这是文档中带有 "Square" 控件的 运行 示例: http://jsbin.com/zuxebev/1/edit?html,output