简体   繁体   English

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

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

So I need to combine choice and prefs 所以我需要结合choiceprefs

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.

相关问题 不知道这个弹出窗口叫什么 - Don't know what this popup is called 如果将被调用方定义为变量,JavaScript函数是否可以知道调用了什么? - Can a JavaScript function know what called it if the callee was defined as a variable? 我不知道要在此代码中更改什么才能使其正常工作 - I don't know what to change in this code for it to work 这个变量类型叫什么? - What is this variable type called? 隐藏类中与变量 ID 不匹配的所有元素 - Hide all elements within a class that don't match the ID of a variable 如果我不知道变量的类型,如何从变量中清除以前的数据(可能是数组,对象或基元) - how to clear previous data from variable if i don't know the type of variable(may be array,object or primitive) 如果我不知道 javascript 中的完整变量名,如何找到变量/数组 - How find variable/array if I don't know full variable name in javascript foreach之前的Javascript分配(我不知道这叫什么) - Javascript assignment before foreach (I don't know what it's called) 想做一个这样的自定义轮播不知道这实际上叫什么? - want to make a custom carousel like this don't know what this is called actually? 如果我没有在javascript中的变量中分配新的图片,该怎么办 - What happens if I don't assign new Image in a variable in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM