Select to view content in your preferred language

div out of scope

2867
8
Jump to solution
04-21-2016 06:10 AM
HelenZhou
Frequent Contributor

I have the following code for a customized widget:

widget html: <div data-dojo-attach-point="moreParcelInfo"></div>

In the Widget.js, I have this code to Query some more information about this parcel

queryLocationInfo: function (parcelID) {

         .........

qryTask_SearchID.execute(qry_SearchID, this.showLocationQueryResults, this.qry_SearchIDError);

}

showLocationQueryResults: function (results) {

.......

     this.moreParcelInfo.innerHTML = resultItems;

}

In this function, this.moreParcelInfo is undefined. Does it mean this.moreParcelInfo is out of scope of the widget? How to fix it? Thanks

Helen

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Helen,

  Don't forget to mark this question as answered by clicking the "Correct Answer" link on the thread that answered your question.

View solution in original post

0 Kudos
8 Replies
RobertScheitlin__GISP
MVP Emeritus

Helen,

  You use lang.hitch.

qryTask_SearchID.execute(qry_SearchID, this.showLocationQueryResults, lang.hitch(this, this.qry_SearchIDError));
HelenZhou
Frequent Contributor

Thank you so much, Robert. It works. By the way, I really like your customized widgets. They are very useful.

Helen

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

  Don't forget to mark this question as answered by clicking the "Correct Answer" link on the thread that answered your question.

0 Kudos
HelenZhou
Frequent Contributor

Robert, I don't know if I need to start a new thread or I can continue to this thread. It is another issue with out of scope.

The error message from Chrome debugging tool: this.showLocationQueryResults is not a function(…)  and this.LocationInfo is undefined too

Can you help? Thanks

Helen

Here is the code:

In Widget.html: <div data-dojo-attach-point="LocationInfo" ></div>

in Widget.js:

queryLocationInfo: function (parcelID) {

          xhr("http://tst-gis4.city.arl/wabdatasupport/SearchAuxiliary.aspx", {

              handleAs: "text",

              query: { parcelid: parcelID },

              method: "POST"

          }).then(function (data) {

             lang.hitch(this, this.showLocationQueryResults(data));

          ------I am able to see the "data"-------------

          ------but the error from Chrome debugging tool: this.showLocationQueryResults is not a function(…)

           --------and this.LocationInfo is undefined too

         }, function (err) {

              // Handle the error condition

              var err;

          }, function (evt) {

              // Handle a progress event from the request if the

              // browser supports XHR2

          });

},

showLocationQueryResults: function (results) {

},

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

  Anytime you have a function then that functions code block is a different scope then the code block that it is called in so you need to use lang.hitch in front of the function keyword.

0 Kudos
HelenZhou
Frequent Contributor

Thank you, Robert, for quick reply.

Yes, I use "lang.hitch(this, this.showLocationQueryResults(data));". But is still not working.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Helen,

  But the line right above that has a function that is not hitched.

0 Kudos
HelenZhou
Frequent Contributor

Robert,

I have worked it with the correct syntax:

lang.hitch(this, function(data){

              lang.hitch(this, this.showLocationQueryResults(data));

          }),Thanks you so much for help.

0 Kudos