【问题标题】:polymer binded value can't change聚合物结合值不能改变
【发布时间】:2015-05-29 23:49:14
【问题描述】:

单击按钮时如何更改按钮内容? 在函数中我可以更改绑定的值吗?

<dom-module id="my-facebook-login-button">
<template>
<paper-button on-click="facebookLogin">{{loginButton}}</paper-button>
</template>
</dom-module>
<script>
(function() {
Polymer({
  is: 'my-facebook-login-button',
  properties: {
    loginButton: {
      type: String,
      value: 'Login with facebook',
      notify: true 
    }
  },
facebookLogin: function() {
var ref = new Firebase("https://sizzling-heat-4021.firebaseio.com/");
ref.authWithOAuthPopup("facebook", function (error, authData) {
if (error) {
  console.log("Login Failed!", error);
} else {
  console.log("Authenticated successfully with payload:", authData);    
    app.user=authData;
    this.loginButton='Loged in';
}
});
},
});

})();
</script>

this.loginButton='已登录'不要更改按钮内容

【问题讨论】:

  • 只是盲拍,this.loginButton.value = 'Loged in'; 有效吗?
  • 您是否尝试将this 绑定到您的function (error, authdata) 中?喜欢function() {}.bind(this)

标签: javascript data-binding firebase polymer


【解决方案1】:

尼尔在他的评论中给出了正确的答案。使用绑定。更新功能如下:

facebookLogin: function() {
  var ref = new Firebase("https://sizzling-heat-4021.firebaseio.com/");
  ref.authWithOAuthPopup("facebook", function (error, authData) {
    if (error) {
      console.log("Login Failed!", error);
    } else {
      console.log("Authenticated successfully with payload:", authData);    
      app.user=authData;
      this.loginButton='Logged in';
    }
  }.bind(this));
},

【讨论】:

    猜你喜欢
    • 2017-12-21
    • 2014-12-24
    • 1970-01-01
    • 2014-08-25
    • 1970-01-01
    • 2017-02-16
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多