2016-07-28 20 views
0

属性の関数ではありません。ポリマー要素内ポリマービヘイビアに引数を渡すことは可能ですか?

、私はこのようなものがあります:

_setError : function(query) { 
      var elems = Array.prototype.slice.call(Polymer.dom(this.root).querySelectorAll(query)); 
      elems.forEach(function(element) { 
       element.setAttribute('invalid', ''); 

      }); 
     } 

すべて:今、私はにこのような機能を持っている別のファイルを振る舞いを定義したい

this.$.register.addEventListener('iron-form-presubmit', 
        function() { 
         //Hides the element... 
         this.$$('#js-error-username-invalid, #js-error-message').setAttribute('style', 'display:none'); 
         //Removes the invalid attribute 
         setInvalid(this.root, false); 
        }); 

       //What to do when a form returns an error, such as the username does not exist. 
       this.$.register.addEventListener('iron-form-error', function (event) { 
        //Sends invalid to everyone. 
        setInvalid(this.root, true); 
        console.log(event); 
        this.$$("#js-error-message").removeAttribute('style'); 
        this.$$("#js-error-message").innerHTML = event.detail.request.xhr.response.error_description 
       }); 

をそれらのquerySelectors、私は引数としてそれらを渡すので、私はフォームを持っているほとんどどこでもこのロジックを再利用できるようにしたいと思います。私はいくつかのファイルを掘り下げようとしましたが、私を助けてくれたものは見つかりませんでした。

答えて

0

回答はとても簡単だった:

あなたが動作している場合:

MyBehavior.FormSubmit_hello("Hi :D"); 

MyBehavior.FormSubmit = { 
     _hello : function(ma) { 
      alert(ma); 
     }, 

をちょうどこのようにそれを呼び出します

関連する問題