2016-05-24 6 views
1

私はあなたが私を助けることを願っています。AngularJSビューで複数のng-disabledパラメータが機能しない - &&(および)および|| (または)

私はそれが簡単な解決策でなければならないと思いますし、複数の方法(括弧内のオプションなど)を試しましたが、うまく動作しない両方のパラメータを取得します。

私は単一のパラメータを使用するとうまく動作します。

これは私が達成しようとしているものです: 私の最初のドロップダウンフィールドの選択はどちらかである週または月、ダウン提出横のドロップを有効にする必要があります。

私が言及したように;単一のパラメータで動作します。例:

ng-disabled="reportSettingsData.ReportFrequencyName.ReportFrequencyType != Enum.ReportFrequency.Monthly" 

しかし、|| (または)のミックスで、それがすべてで動作していない。ここで

ng-disabled="reportSettingsData.ReportFrequencyName.ReportFrequencyType != Enum.ReportFrequency.Monthly || reportSettingsData.ReportFrequencyName.ReportFrequencyType != Enum.ReportFrequency.Weekly" 

は私のビューのフィールドダウン私の2ドロップです:

<!-- Frequency --> 
    <div class="col-md-3"> 
     <label>Frequency</label> 
     <div class="input-dropdown"> 
      <cc-dropdown cc-placeholder="Report Frequency" 
          ng-model="reportSettingsData.ReportFrequencyName" 
          ng-options="reportSettingsData.SelectableReportFrequencyNames" 
          ng-change="frequencyChanged()" 
          cc-fields="ReportFrequencyName" 
          cc-key-field="ReportFrequencyId" 
          cc-allow-search="reportSettingsData.SelectableReportFrequencyNames != null && reportSettingsData.SelectableReportFrequencyNames.length > 5" 
          name="iFrequencyName"> 
      </cc-dropdown> 
     </div> 
    </div> 
    <div class="col-md-3"> 
     <label>Frequency Options</label> 
     <div class="input-dropdown"> 
      <cc-dropdown cc-placeholder="Report Frequency Option" 
          ng-model="reportSettingsData.ReportFrequencySelectionName" 
          ng-options="reportSettingsData.SelectableReportFrequencySelectionNames" 
          ng-disabled="reportSettingsData.ReportFrequencyName.ReportFrequencyType != Enum.ReportFrequency.Monthly || reportSettingsData.ReportFrequencyName.ReportFrequencyType != Enum.ReportFrequency.Weekly" 
          cc-fields="ReportFrequencySelectionName" 
          cc-key-field="ReportFrequencySelectionId" 
          cc-allow-search="true" 
          name="iFrequencySelections"> 
      </cc-dropdown> 
     </div> 
    </div> 

は、事前にありがとうございます!

+0

なぜダウン投票?私は研究を行い、複数の方法を試みました。 – onmyway

答えて

1

これ以上の調査と支援の後、答えがあります。

私は単に|| (または)演算子を& &(および)演算子に変換します。

ng-disabled="reportSettingsData.ReportFrequencyName.ReportFrequencyType != Enum.ReportFrequency.Weekly && reportSettingsData.ReportFrequencyName.ReportFrequencyType != Enum.ReportFrequency.Monthly" 

論理的に(考えてみてください)、||

しかし、私はの妥当性を評価するために、NOT(!=)を使用していますので

「が 『この』や 『こと』するとき、フィールドを有効にする」:私は基本的に言っているように、働いているはずです私の条件とng-disabledの両方の指示が真実である(私が知っているのは、これが私がウサギの穴を掘ったところです)。

つまり、そして私が間違っている場合は、私を助けてください -

(これは私がそれの意味を作っていますどのように「それは 『これがない』と 『ないこと』されたときにフィールドを無効にします」 !)。

ここでは、||そして&より良い&:

私はこの少し説明を愛して:

JavaScriptの意志短絡評価 条件がTrueまたはFalseになるとき、それは知っている瞬間。

http://www.grauw.nl/blog/entry/510

https://en.wikipedia.org/wiki/Short-circuit_evaluation

http://www.bennadel.com/blog/2789-be-careful-with-compound-conditions-in-angularjs-and-javascript-in-general.htm

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators