Search code examples
ajaxpolymer

not able to get one polymer property value into another polymer property which is returning value as a function


I have below piece of code which i am using to call http request using iron ajax with polymer so passing the value of body and last-response using polymer properties.as we can see here we have requestBody polymer property in this we are returning no of values in requestBody all values are hardcodes like start and end and name under tag.

Now my problem is i want to get uri value in name instead of passing of hardcode value in name i want to get uri value dynamically under the name parameter whenever uri value change .

   <iron-ajax
      id="Request"
      method="POST"
      content-type="application/json"
      auto
      url="/api/series/v1/points"
      last-response="{{Data123}}"
      body="{{requestBody}}">
    </iron-ajax>

 Polymer({
      is: 'test-view',

      behaviors: [GlobalsBehaviour],

      properties: {

  uri: {
          type: String,
          observer: '_uriChanged'
        },

 requestBody:{
          type: Object,
          value: function() {
            return {
              "start": 11111,
               "end": 123333,
              "tags": [
                {
                "name" : "/asset/India/rotor",
                }
              ]
            };
          }
        }, 

 Data123:{
            type: Object,
            observer: '_formateData'
        },

  observers: [
      '_uriChanged(globals.uri)'
    ],

i have tried like this "name" : this.uri,and "name" : uri, but not able to get value Note : uri is coming from another polymer component and in some case its coming from global set variable.

Please let me know how can i get uri value in name attribute which is in requestBody property


Solution

  • First remove auto from iron-ajax tag, then change _uriChanged function as follows

    _uriChanged: function(uri) {
      this.set('requestBody.tags.0.name', uri);
      this.$.Request.generateRequest();
    }