2012-12-20 13 views
1

在Flex移動應用程序(或任何Flex 4應用程序)中 - 如何根據其他兩個字段的內容啓用/禁用按鈕?僅當2個TextInput字段不爲空時啓用按鈕 - 附帶代碼和屏幕截圖

enter image description here

我貼我的下面很簡單的測試代碼和它存在的問題是在Flash Builder 4.7的語法錯誤:The entity name must immediately follow the '&' in the entity reference. - 這可能意味着符號是一個特殊字符,但如何解決這個問題(大概頻繁)問題?

TestApp.mxml:

<?xml version="1.0" encoding="utf-8"?> 
<s:ViewNavigatorApplication 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    firstView="views.Home" 
    applicationDPI="160"> 
</s:ViewNavigatorApplication> 

的意見/ Home.mxml:

<?xml version="1.0" encoding="utf-8"?> 
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     title="How to enable Login button?"> 

    <s:layout> 
     <s:VerticalLayout paddingTop="8" 
      horizontalAlign="center" gap="8" /> 
    </s:layout> 

    <s:Label text="Username:" /> 
    <s:TextInput id="_username" /> 
    <s:Label text="Password:" /> 
    <s:TextInput id="_password" /> 

    <s:Button id="_login" 
       label="Login" 
       enabled="{_username.text.length > 0 && _password.text.length > 0}" /> 
</s:View> 

回答

3

,當你把它寫CDATA之外在MXML中,您應&amp;&amp;取代&&

這也是更好地使用_username.text!=''而不是_username.text.length > 0因爲它會在運行時導致警告視爲text不是此事件並不能報告length變化。但是,它會更新按鈕的可用性,因爲text將自行更改,TextInput將報告它導致綁定更新。

0

使用綁定表達式時。 MXML不考慮& &而寫你的表達

&放大器; amp; & amp;

.... mxml也不讀取轉義字符例如\ t爲標籤...寧可在動作寫你的表達,然後使用數據綁定.cheers ;-)

相關問題