更改{{variable}}中的一个变量(不知道它叫什么)
Change a variable within a {{variable}} (don't know what that is called)
我需要根据用户点击将变量"prefs"更改为"easy,medium,or hard"。
示例:这个
{{choice.prefs.title}}
需要更改为{{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>
手动键入{{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.book1
或allbooks.book2
所以我需要结合choice
和prefs
感谢:)
您可以执行以下操作:
<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
(引用变量对象属性时使用[]
表示法,而不是.
表示法)
相关文章:
- 元素在我的代码中不会.fadeTo.Don'I don’我不知道;s错误的JavaScript、JQuery、H
- 我可以'我似乎不知道如何修复javascript中的两个lint.有人能帮我理解吗
- 在不知道深度或父属性的情况下从对象中删除属性
- Steam Web API:I'我不知道该如何处理这个看起来像哈希的url来生成图像
- 使用.on动态添加jquery/js不知道的html元素
- Jquery-每个循环不更新变量
- 这个旋钮没有更新;我不知道为什么
- 我不知道为什么我的代码是错误的?又有什么错
- Javascript如何知道变量的类型
- 如何在不知道关键字的情况下访问javascript对象值
- 我不知道我的编码有什么问题.(JavaScript)
- 变量不起作用(不知道为什么)javascript
- N00B 帮助 - 用于检查输入是否可以形成直角三角形的脚本.搞砸了我的警报,不知道我是否有变量
- 更改{{variable}}中的一个变量(不知道它叫什么)
- 如何从变量中清除以前的数据如果我不'不知道变量的类型(可以是数组、对象或基元)
- Nooblyf,javascript,由 3 个变量控制的简单循环,不知道为什么它在 1 次迭代后停止循环
- JavaScript内存泄漏——不知道如何清除变量
- javascript的设计模式,当你不知道一个属性将是一个变量还是一个函数
- JavaScript/不知道如何使用变量
- JQuery新手,不知道如何使用局部变量(使用greasemonkey)