Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更改{{variable}}中的变量(不知道它叫什么)_Javascript_Jquery_Angularjs_Ionic Framework_Ionic - Fatal编程技术网

Javascript 更改{{variable}}中的变量(不知道它叫什么)

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

我需要根据用户点击将变量“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>

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