arcgis flexviewer中由Application向widget傳值

來源:互聯網
上載者:User

標籤:

arcgis flexviewer所有的小組件類均繼承自com.esri.viewer.BaseWidget基類,而BaseWidget又繼承了com.esri.viewer.IBaseWidget介面。所有的小組件又由WidgetManager類進行管理。因此,要實現從Application向widget傳值,需要經由WidgetManager完成。例如,使用者登入時記錄了使用者名稱,在widget中需要對使用者名稱進行驗證,可通過下述步驟將使用者名稱(字串)傳遞到所有的繼承了上述小組件基類的widget中。

1、修改IBaseWidget介面檔案,增加下述函數定義:

function set userName(value:String):void;function get userName():String;

2、在基類BaseWidget中實現上述方法:

private var _username:String;[Bindable]public function get userName():String{    return _username;}public function set userName(value:String):void{    _username = value;}

3、按照上述方法,在WidgetManager中定義相關的變數和屬性存取器,如下:

private var user_name:String;[Bindable]public function set userName(value:String):void{      user_name = value;  }[Bindable]public function get userName():String{      return user_name;}

4、假設Application中(一般為首頁)有一個名為userNameStr的字串變數,在WidgetManager的MXML聲明中做如下定義:

<viewer:widgetManager>     <managers:WidgetManager id="widgetManager" userName="{userNameStr}"/></viewer:widgetManager>

5、在WidgetManager類的createWidget函數中,在widget.map = map;語句之後添加下述代碼:

widget.userName = this.userName;

6、測試。使用者名稱為admin,在小組件中添加:

Alert.show("Widget: " + this.userName);

執行相關代碼,可見到來自小組件的訊息框:

 

DONE.

 

arcgis flexviewer中由Application向widget傳值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.