簡體   English   中英

在{{variable}}中更改變量(不知道該叫什么)

[英]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.book1allbooks.book2

所以我需要結合choiceprefs

謝謝:)

您可以執行以下操作:

<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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM