2016-11-11 5 views
0

iron-ajax経由でAjaxリクエストからフェッチした配列に、配列を取り込もうとしています。 自分のプロパティ、ウォッチウィンドウにアクセスしようとすると以下は Ajaxリクエスト内でPolymer v1.xプロパティを変更する方法

が、私は私の問題を説明するために再作成はほとんどの例である「利用できません」が表示されます。

私-component.htmlの外に表示された場合、私は私の「都市のプロパティを読み込むことができますどのように

<link rel="import" href="../../bower_components/polymer/polymer.html"> 
<link rel="import" href="../../bower_components/iron-ajax/iron-ajax.html"> 
<link rel="import" href="../../bower_components/app-storage/app-localstorage/app-localstorage-document.html"> 
<link rel="import" href="../../bower_components/paper-dropdown-menu/paper-dropdown-menu.html"> 


<dom-module id="my-component"> 
    <template> 
     <div> 
      <paper-dropdown-menu 
        id="location" label="Ubicaci&oacute;n" 
        value="{{vehicle.location}}"> 
      </paper-dropdown-menu> 
      <paper-dropdown-menu id="city" label="Ciudad"> 
       <paper-menu 
         class="dropdown-content" 
         selected="{{city.city_code}}" 
         attr-for-selected="value" 
         on-iron-select="estadoSeleccionado"> 
        <template id="" is="dom-repeat" items="[[opcionesDisponibilidad]]" as="i"> 
         <paper-item value="[[i.valor]]">[[i.texto]]</paper-item> 
        </template> 
       </paper-menu> 
      </paper-dropdown-menu> 
     </div> 
     <iron-ajax 
       id="ajax" 
       method="GET" 
       url="http://localhost:8080/ws.asmx" 
       params="" 
       content-type="application/x-www-form-urlencoded; charset=UTF-8" 
       handle-as="text" 
       on-response="handlecities" 
       debounce-duration="300"> 
     </iron-ajax> 
     <app-localstorage-document id="localStorageElement" key="myapp.login_data" data="{{loginInfo}}"></app-localstorage-document> 
    </template> 
    <script> 
     Polymer({ 
      is: "my-component", 
      properties:{ 
       vehicle: { 
        type: Object, 
        value:{ 
         id: "", 
         plate: "", 
         location: "" 
        } 
       }, 
       cities:{ 
        notify: true, 
        type: Array, 
        value: [{city_code:'0', city_name:'-'}] 
       } 
      }, 
      ready:function() { 
       this.querycities(); 
      }, 
      querycities: function() { 
       if (this.$.localStorageElement.storage['myapp.login_data']){ 
        this.$.loginInfo = JSON.parse(this.$.localStorageElement.storage['myapp.login_data']); 
       } else return false; 
       this.$.ajax.url = this.$.ajax.url + "/listadoCiudades"; 
       this.$.ajax.verbose = true; 
       this.$.ajax._boundHandleResponse = this.handlecities; 
       this.$.ajax.params = {dispositivo:'12345', credencial: this.$.loginInfo.cred}; 
       this.$.ajax.generateRequest(); 
      }, 
      handlecities: function (request) { 
       console.log(request.response); 
       var xPath = new SoftXpath(); 
       xPath.registerNamespace("",""); 
       xPath.loadXML(request.response); 
       var cities = xPath.selectNodes("//Ciudad//*[self::Codigo|self::Nombre]"); 
       var xPathElement = new SoftXpath(); 
       if (cities){ 
        for(var i = 1; i < cities.length;i++){ 
         var c = new Object(); 
         c.Codigo = cities[i-1].text; 
         c.Nombre = cities[i].text; 

         this.$.cities.push(c);// <---- Here I have not access to my polymer property ' cities '. 

         //How to update my polymer var cities ?? 
         //Tried also with: 
         // this.cities --> undefined 
         // this.$$('#myassignedId').cities --> undefined 
        } 
       } 
      } 
     }) 
    </script> 
</dom-module> 

スコープ?

+0

'handlecities(のための1つを定義する - 私は)'サーバ応答から解析結果を 'this.cities'を設定する必要があります。 'this.cities'はあらかじめ存在する必要はありません。ウォッチ式の問題は、詳細情報なしではデバッグできません。どのような表現を使用しましたか?式を表示するためにどこにブレークポイントを設定しましたか?式のターゲットプロパティを設定する関連するコードは何ですか? – tony19

答えて

0

まあ、 あまりにも多くの試行錯誤の後、最終的に私はエラーの原因を発見しました。

ライン65:

this.$.ajax._boundHandleResponse = this.handlecities; 

は、その行を削除し、すべての私のポリマーの属性が正常に戻りました。

私はいくつかのAjaxリクエストに対してコンポーネントを再利用しようとしていたので、その文を使用していました。 'handlecities'も属性として指定されているため、冗長性があります(再利用の意図がない場合のみ)。私はまだカスタムハンドラを定義するコンポーネントを再利用する方法がわかりませんが、何らかの理由で上記の文を使用すると、すべてのポリマープロパティが失われます。

だから、その間にいくつかのAJAXコンポーネントを各AJAXリクエスト

関連する問題