繁体   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