Javascript 更改{{variable}}中的变量(不知道它叫什么)
我需要根据用户点击将变量“prefs”更改为“easy、medium或hard” 例如: 这个 需要换成Javascript 更改{{variable}}中的变量(不知道它叫什么),javascript,jquery,angularjs,ionic-framework,ionic,Javascript,Jquery,Angularjs,Ionic Framework,Ionic,我需要根据用户点击将变量“prefs”更改为“easy、medium或hard” 例如: 这个 需要换成 {{choice.easy.price}}或{{choice.medium.price}或{{choice.hard.price}} 基于用户单击的按钮 <button class="button button-stable" ng-click="prefs="easy"")>Change to Easy</button> </div> <butt
{{choice.easy.price}}
或{{choice.medium.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>
选项由一个函数分配,该函数仅根据用户单击将选项设置为allbooks.book1
或allbooks.book2
因此,我需要将选项
和首选项
谢谢:)您可以这样做:
<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>
更改为Easy
换成中等
变硬
并使用:$scope[prefs].title
而不是$scope.prefs.title
(引用变量对象属性时,请使用
[]
符号而不是
符号)为什么要更改变量?更改值您能否详细说明(使用一些代码;)。。。。我以为这就是我对“prefs='easy'”所做的,只是更改变量中的值而不是变量将prefs='easy'
更改prefs
对象的prefs
属性?prefs='easy'
将设置变量prefs
的值,此处引用:$scope[prefs].title
但我仍然需要“选择”,因为这是访问阵列的特定部分所必需的。。。那么它将是“choice[prefs].title”……控制器中的数组本质上是这样的:请参见编辑@AvijitGupta@MehdiN请澄清。您的编辑没有提示有用的内容,并且被审阅者拒绝。对不起,您能看到我对我的问题的编辑吗。。。(我在控制器中添加了数组)…基本上,我需要保留选项
部分并添加prefs
部分,但在您的解决方案中,您取消了选项
并将$scope
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"}
},
}
<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>