[英]Change a variable within a {{variable}} (don't know what that is called)
I need to change the variable "prefs" to either "easy, medium, or hard" based on user click. 我需要根据用户点击将变量“ prefs”更改为“ easy,medium或hard”。
Example: THIS 示例:THIS
{{choice.prefs.title}}
NEEDS TO CHANGE TO {{choice.easy.price}}
or {{choice.medium.price}}
or {{choice.hard.price}}
需要更改为{{choice.easy.price}}
{{choice.medium.price}}
或{{choice.hard.price}}
或{{choice.hard.price}}
based on which button is clicked by the user 根据用户单击哪个按钮
<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>
Manually typing {{choice.easy.price}}
works but {{choice.prefs.price}}
and ng-click="pref='easy'"
does not work 手动输入{{choice.easy.price}}
可以,但是{{choice.prefs.price}}
和ng-click="pref='easy'"
不起作用
Thanks for the help in advance 我在这里先向您的帮助表示感谢
EDIT: The array I am trying to access in my controller looks like this 编辑:我试图在控制器中访问的数组看起来像这样
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"}
},
}
Choice is assigned by a function that simply sets choice to allbooks.book1
or allbooks.book2
based on user clicks 选择是由一个功能分配的,该功能仅根据用户点击将选择设置为allbooks.book1
或allbooks.book2
So I need to combine choice
and prefs
所以我需要结合choice
和prefs
Thanks:) 谢谢:)
You may do something like this: 您可以执行以下操作:
<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>
and use: $scope[prefs].title
instead of $scope.prefs.title
(Use []
notation instead of the .
notation when referencing variable object properties) 并使用: $scope[prefs].title
代替$scope.prefs.title
(在引用变量对象属性时,使用[]
表示法代替.
表示法)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.