[英]Change a variable within a {{variable}} (don't know what that is called)
我需要根據用戶點擊將變量“ prefs”更改為“ easy,medium或hard”。
示例:THIS
{{choice.prefs.title}}
需要更改為{{choice.easy.price}}
{{choice.medium.price}}
或{{choice.hard.price}}
或{{choice.hard.price}}
根據用戶單擊哪個按鈕
<button class="button button-stable" ng-click="prefs="easy"")>Change to Easy</button>
</div>
<button class="button button-stable" ng-click="diff='normal'">Change to Medium</button>
</div>
<button class="button button-stable" ng-click="diff='hard'">Change to Hard</button>
</div>
手動輸入{{choice.easy.price}}
可以,但是{{choice.prefs.price}}
和ng-click="pref='easy'"
不起作用
我在這里先向您的幫助表示感謝
編輯:我試圖在控制器中訪問的數組看起來像這樣
allbooks={
book1:{
easy{title:"whatever"},
medium{title:"hello"},
hard{title:"another"}
},
book2:{
easy{title:"whatever"},
medium{title:"hello"},
hard{title:"another"}
},
book3:{
easy{title:"whatever"},
medium{title:"hello"},
hard{title:"another"}
},
}
選擇是由一個功能分配的,該功能僅根據用戶點擊將選擇設置為allbooks.book1
或allbooks.book2
所以我需要結合choice
和prefs
謝謝:)
您可以執行以下操作:
<button class="button button-stable" ng-click="prefs='easy'")>Change to Easy</button>
</div>
<button class="button button-stable" ng-click="prefs='normal'">Change to Medium</button>
</div>
<button class="button button-stable" ng-click="prefs='hard'">Change to Hard</button>
</div>
並使用: $scope[prefs].title
代替$scope.prefs.title
(在引用變量對象屬性時,使用[]
表示法代替.
表示法)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.