2012-07-11 9 views
5

यदि बूलियन गलत है तो मैं #view सहायक के साथ एक क्लास को कैसे देख सकता हूं?सहायक देखें: क्लाउड बाइंडिंग अगर बूलियन झूठा है

// this is working 
{{#view App.MyView controllerBinding="this" classBinding="controller.content.isActive"}} 
    <div>test</div> 
{{/view}} 

// and this is what i want: 
{{#view App.MyView controllerBinding="this" classBinding="!controller.content.isActive:is-not-active"}} 
    <div>test</div> 
{{/view}} 

मैं देखने के लिए एक वर्ग के नाम के रूप में is-not-active बाध्य करने के लिए, अगर controller.content.isActive गलत है चाहता हूँ।

मैं दृश्य पर एक साधारण इन्वर्टर फ़ंक्शन कर सकता हूं, लेकिन मेरे पास एक बेहतर तरीका है।

उत्तर

9

अद्यतन: पुल अनुरोध, विलय कर दिया गया है ताकि आप एक false मूल्य इस तरह के लिए एक वर्ग जोड़ सकते हैं:

{{#view App.MyView controllerBinding="this" 
    classBinding="controller.content.isActive:is-active:is-not-active"}} 
{{/view}} 

आप एक वर्ग को जोड़ने के लिए नहीं करना चाहते हैं, तो मूल्य true है , तो आप निम्न सिंटैक्स का उपयोग कर सकते हैं:

{{#view App.MyView controllerBinding="this" 
    classBinding="controller.content.isActive::is-not-active"}} 
{{/view}} 

मैं (दृश्य पर एक संपत्ति बन जाएगा आप पहले से ही करते हैं अपने पलटनेवाला के साथ) और यह करने के लिए बाध्य:

Handlebars:

{{#view App.MyView controllerBinding="this" classBinding="isNotActive"}} 
    <div>test</div> 
{{/view}} 

जावास्क्रिप्ट:

App.MyView = Ember.View.extend({ 
    isNotActive: Ember.Binding.not('controller.content.isActive') 
}); 

मैं एक Pull Request जो अभी तक विलय कर नहीं किया गया है बनाने के है लेकिन यह इस मुद्दे को संबोधित करता है और इसे इस तरह हल करेगा:

{{#view App.MyView controllerBinding="this" 
    classBinding="controller.content.isActive:is-active:is-not-active"}} 
    <div>test</div> 
{{/view}} 
+0

धन्यवाद। यह एक "इन्वर्टर" के साथ मेरा मतलब है। मैं अब इसका उपयोग करूंगा और पुल अनुरोध के लिए आशा करता हूं। – Lux

संबंधित मुद्दे