【问题标题】:how to bind user input value in textField with propetry "text" of the link(sapui5)如何将文本字段中的用户输入值与链接的属性“文本”绑定(sapui5)
【发布时间】:2014-02-10 11:17:15
【问题描述】:

我有一个文本字段:

  var favInput = new sap.ui.commons.TextField("tfFavorites",{
  value : 'Give a name to the favorite....',
  imeMode: sap.ui.core.ImeMode.Active,
 editable: true  });

我有一个按钮:

 var saveFavorButton = new sap.ui.commons.Button({  text : "Create new favorite" });

按下按钮后,我想构建一个“createNewFavorite”函数,该函数将创建一个带有用户文本输入名称的链接。例如:

var myFavorites1 = new sap.ui.commons.Link("myfav1",{
      text: "my favorite 1",
              });

如何创建“createNewFavorite”功能?非常感谢!

【问题讨论】:

    标签: input hyperlink textfield sapui5


    【解决方案1】:

    你可以使用类似的东西:

    saveFavorButton.attachPress(function() {
        var myFavorites1 = new sap.ui.commons.Link("myfav1",{
            text: favInput.getValue()
        });
        //now you just need to add the new control to your view
    });
    

    但更好的方法是创建一个 (JSON) 模型,然后将其绑定到您的 TextField,然后您可以扩展和/或缩小该模型以存储更多收藏夹

    【讨论】:

      【解决方案2】:

      在按钮的属性中,您可以添加一个属性 PRESS,您可以在其中定义您的函数 createNewFavorite,如下所示:

      var saveFavorButton = new sap.ui.commons.Button( {
      text : "创建新收藏", 按:函数() { var myFavorites1 = new sap.ui.commons.Link("myfav1", { 文本:favInput.getValue() }); } });

      或者你可以写“press : createNewFavorite”,你可以在控制器中定义这个函数createNewFavorite。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-04
        • 1970-01-01
        • 2014-01-07
        • 1970-01-01
        • 1970-01-01
        • 2016-08-16
        • 1970-01-01
        • 2023-03-12
        相关资源
        最近更新 更多