2017-12-22 19 views
0

저는 프로그래밍 및 polymer.js 학습을 처음 접했습니다. 현재 사용자에게 서명하기 위해 간단한 웹 응용 프로그램에서 작업하고 있습니다. 현재 양식을 제출할 때마다 아래에 표시된 형식과 완전한 JSON 개체를 제출합니다. 대신 JSON 객체에 양식 값 제출

{ 
    email: "[email protected]", 
    password: "password" 
} 

는 ... 여기

{ 
    "email":"[email protected]", 
    "password":"password" 
} 
내 코드입니다 :

<form action="http://httpbin.org/post" method="post"> 

    <sign-in-input email="{{_email}}" password="{{_password}}"></sign-in-input> 

    <input class = "paperbtn" type="submit" value="Sign in"> 

    <input name="email" value="[[_email]]" hidden> 
    <input name="password" value="[[_password]]" hidden> 

</form> 

로그인-input.html :

<dom-module id="sign-in-input"> 
<template> 
     <paper-input label = "Email" id = "email" required></paper-input> 
     <paper-input label = "Password" id = "password" required></paper-input> 
</template> 

<script> 
    Polymer({ 
    is: 'sign-in-input', 

    properties: { 
     email: { 
     type: String, 
     notify: true 
     }, 
     password: { 
     type: String, 
     notify: true 
     } 
    }, 

    listeners: { 
     'input': '_onInput' 
    }, 

    _onInput: function() { 
     this.email = this.$.email.value.trim(); 
     this.password = this.$.password.value.trim(); 
    } 
    }); 
</script> 

+0

문제가 표시되지 않습니다. 무엇이 문제인가? – FrankerZ

+0

무엇이 문제인가? – Liam

+0

나는이 문제가'email : "[email protected]"이 "email"이어야한다고 생각한다 : "[email protected]"'분명하지만 확실하지 않다 – Liam

답변

0

문자열을 보낼 때 개체 (obj)를 보냈습니다.

보낼 개체에 JSON.stringify(ob)을 사용 했습니까?

당신이 묻지 않은 다른 것들. this.set이 값을 업데이트하는 폴리머에서 이벤트를 전송하기 때문에


_onInput: function() { 
    this.email = this.$.email.value.trim(); 
    this.password = this.$.password.value.trim(); 
} 

당신은 this.set('email', this.$.email.value.trim()를 사용해야합니다. 지금은 문제가되지 않지만 계속해서 this.[property]을 사용하면 다른 요소가 될 수 있습니다.

listeners: { 
    'input': '_onInput' 
}, 

_onInput: function() { 
    this.email = this.$.email.value.trim(); 
    this.password = this.$.password.value.trim(); 
} 

그것은 같은 모양 :

<paper-input label="Email" id="email" value="{{email::input}}" required></paper-input> 
<paper-input label="Password" id="password" value="{{password::change}}" required></paper-input> 

내가 사용하는 폴리머 청취자의 두 종류


<paper-input label = "Email" id = "email" required></paper-input> 
    <paper-input label = "Password" id = "password" required></paper-input> 

당신은 사용하지 않는 것이, 바로 다음에 리스너를 바인딩 할 수 있습니다 , 입력 및 변경. 둘 중 하나를 사용할 수 있습니다.