LIFO究竟是什么意思?(What does LIFO really mean?)
如本教程中所述: http : //www.learncpp.com/cpp-tutorial/79-the-stack-and-the-heap/
在计算机编程中,堆栈是容纳其他变量的容器(很像数组)。 但是,虽然数组允许您按照任何顺序访问和修改元素,但堆栈更受限制。 可以在堆栈上执行的操作与上面的操作相同:
1)查看堆栈顶部的项目(通常通过名为top()的函数完成)2)从堆栈中取出顶部项目(通过名为pop()的函数完成)3)在项目顶部放置一个新项目堆栈(通过名为push()的函数完成)
但是如果我在C ++中定义了两个变量,我就不必按照相同的定义顺序使用它们:
例:
int main() { int a; int b; b = 5; a = 6; }
这段代码有问题吗? 我可以按照我喜欢的任何顺序使用它们! 我不必先使用a,然后使用b 。
我误会了什么吗? 它是什么?
As mentioned in this tutorial: http://www.learncpp.com/cpp-tutorial/79-the-stack-and-the-heap/
In computer programming, a stack is a container that holds other variables (much like an array). However, whereas an array lets you access and modify elements in any order you wish, a stack is more limited. The operations that can be performed on a stack are identical to the ones above:
1) Look at the top item on the stack (usually done via a function called top()) 2) Take the top item off of the stack (done via a function called pop()) 3) Put a new item on top of the stack (done via a function called push())
But if I defined two variables in C++ I do not have to use them in the same order of definition:
Example:
int main() { int a; int b; b = 5; a = 6; }
Is there a problem on this code? I can use them in any order I like!! I do not have to use the a first then the b.
Am I misunderstanding something? What is it?
原文:https://stackoverflow.com/questions/8425718
满意答案
您的代码存在各种问题,但它不会引发错误,因为映射插件使用不当。
范围问题
首先,
fullAddress
是Address
实例的属性,因此您应该在address.
加上它address.
其次,with
binding告诉Knockout寻找不存在的editingPerson.savePerson
。 因此,您必须将绑定更改为根范围,如下所示:click: $root.savePerson
。<!-- current --> inputAddress: <input data-bind="value: fullAddress"> <!-- correct --> inputAddress: <input data-bind="value: address.fullAddress"> <!--current --> <button data-bind="click:savePerson" type="button">Save</button> <!--correct --> <button data-bind="click:$root.savePerson" type="button">Save</button>
还建议使用对象作为构造函数参数,以便更容易与
mapping plugin
结合使用,并且您是否希望省略一个属性。映射插件
映射插件文档明确指出:
对象的所有属性都将转换为可观察对象。
这意味着您不能包含计算的 observable并期望它们正常工作。 实际上,文档中有一部分关于使用计算的observable来扩充JS对象。 我可能错了,但是从我的测试和文档来看,映射的
create
函数似乎不能用于嵌套对象。 在此文档之后,您不需要显式创建所有可观察属性,因为对ko.mapping.fromJS
的单个调用可以实例化它们。 你的新Person
构造函数看起来像这样:function Person(options){ // because these arrays contain nested objects with computed observables, // they should have a special create function var self = this, mapping = { 'amounts': { create: function(options) { return new Amount(options.data); }}, 'address': { create: function(options) { return new Address(options.data); }} }; // instantiates all properties, eg. surname, name, id ko.mapping.fromJS(options, mapping, this); self.fullName = ko.computed(function() { return self.name()+" - "+self.surname(); }); }
另一个次要的'挑选':你只能在命名对象属性上使用映射插件的
create
函数,所以在你原来的小提琴中,插件永远不会找到persons
数组,因为它是数据根。查看完整解决方案的小提琴 。
There are various problems with your code, but it won't throw an error because the mapping plugin is used improperly.
The problem of scope
First,
fullAddress
is a property ofAddress
instances, so you should prefix it withaddress.
Second, thewith
binding tells Knockout to look foreditingPerson.savePerson
which doesn't exist. So you have to change the binding to the root scope, like so:click: $root.savePerson
.<!-- current --> inputAddress: <input data-bind="value: fullAddress"> <!-- correct --> inputAddress: <input data-bind="value: address.fullAddress"> <!--current --> <button data-bind="click:savePerson" type="button">Save</button> <!--correct --> <button data-bind="click:$root.savePerson" type="button">Save</button>
It is also advised to use objects as constructor parameter, allowing for easier use in combination with the
mapping plugin
and should you wish to leave out one property.The mapping plugin
The mapping plugin documentation clearly states that:
All properties of an object are converted into an observable.
This means that you cannot include computed observables and expect them to just work. Indeed, the documentation has a part about augmenting JS objects with computed observables here. I might be wrong, but from my tests and the docs, it doesn't seem so that the
create
functions for mapping can be used for nested objects. Following this documentation, you don't need to create all observable properties explicitly, as a single call toko.mapping.fromJS
can instantiate them. Your newPerson
constructor would look like this:function Person(options){ // because these arrays contain nested objects with computed observables, // they should have a special create function var self = this, mapping = { 'amounts': { create: function(options) { return new Amount(options.data); }}, 'address': { create: function(options) { return new Address(options.data); }} }; // instantiates all properties, eg. surname, name, id ko.mapping.fromJS(options, mapping, this); self.fullName = ko.computed(function() { return self.name()+" - "+self.surname(); }); }
Another minor 'nit-pick': you can only use the mapping plugin's
create
functions on named object properties, so in your original fiddle, the plugin will never find thepersons
array because it is the data root.Check out this fiddle for the complete solution.
相关问答
更多KnockoutJS:使用'html'绑定,新元素不具有约束力(KnockoutJS: Using 'html' binding, new elements not binding)
如何使用knockoutjs映射插件对数据绑定到表?(How to sort data bind to table using knockoutjs mapping plugin?)
knockoutjs映射嵌套元素不绑定(knockoutjs mapping nested elements is not binding)
knockoutjs中的双向绑定(Two way binding in knockoutjs)
在knockoutJS中嵌套的foreach绑定(Nested foreach binding in knockoutJS)
knockoutjs映射选择数据绑定选项(knockoutjs mapping select data-bind options)
Knockoutjs映射 - 没有初始数据(Knockoutjs mapping - without initial data)
KnockoutJS:为虚拟元素使用嵌套的条件if语句(KnockoutJS: Using nested conditional if statements for virtual elements)
knockoutjs在html上使用逻辑或启用绑定(knockoutjs use logical or with enable binding on html)
KnockoutJS Mapping toJS忽略嵌套键(KnockoutJS Mapping toJS ignore nested keys)
相关文章
更多Hadoop究竟是什么?
Collections.unmodifiableMap 这个是什么意思
ext 的store中 baseParams.conditions 是什么意思啊?
这些是什么
弱弱的问一下 java 中的 <= 表示什么意思?
struts2.xml中crud!input什么意思
java是什么
Hive是什么?
shell是什么
JSON是什么?
最新问答
更多如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
linux的常用命令干什么用的
由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
如何交换返回集中的行?(How to swap rows in a return set?)
在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
Java中的不可变类(Immutable class in Java)
WordPress发布查询(WordPress post query)
如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!