如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
我正在使用Ember.js中的表单,并且想要检索所有模型属性的列表,以便我可以在不同时刻拍摄表单状态的快照。 有没有办法获得模型的所有属性列表?
例如,如果我的模型是:
App.User = DS.Model.extend({ name: DS.attr('string'), email: DS.attr('string'), current_password: DS.attr('string'), password: DS.attr('string'), password_confirmation: DS.attr('string'), admin: DS.attr('boolean'), }
然后我想要这样的东西:
> getEmberProps('User') ["name", "email", "current_password", "password", "password_confirmation", "admin"]
I'm working with forms in Ember.js and I want to retrieve a list of all model properties so that I can take snapshots of the state of the form at different moments. Is there a way to get a list of all properties of a model?
For example, if my model is:
App.User = DS.Model.extend({ name: DS.attr('string'), email: DS.attr('string'), current_password: DS.attr('string'), password: DS.attr('string'), password_confirmation: DS.attr('string'), admin: DS.attr('boolean'), }
Then I would like to have something like this:
> getEmberProps('User') ["name", "email", "current_password", "password", "password_confirmation", "admin"]
原文:https://stackoverflow.com/questions/15658442
满意答案
内存页面在您使用它们之前并未实际映射到您的程序。 所有的
malloc
都会保留一个虚拟地址空间的范围。 在您尝试读取或写入物理RAM之前,没有将物理RAM映射到这些虚拟页面。即使您分配全局或堆栈(“自动”)内存,在您触摸它们之前也没有物理页面的映射。
最后,
sizeof()
是在编译时计算的,当编译器不知道OS将在以后做什么时。 所以它只会告诉你对象的预期大小。如果您尝试在每种情况下将内存
memset
为0,您会发现事情会表现得非常不同。 另外,你可能想尝试一下calloc
,它将它的内存归零。Memory pages aren't actually mapped to your program until you use them. All
malloc
does is reserve a range of the virtual address space. No physical RAM is mapped to those virtual pages until you try to read or write them.Even when you allocate global or stack ("automatic") memory, there's no mapping of physical pages until you touch them.
Finally,
sizeof()
is evaluated at compile time, when the compiler has no idea what the OS will do later. So it will just tell you the expected size of the object.You'll find that things will behave very differently if you try to
memset
the memory to 0 in each of your cases. Also, you might want to trycalloc
, which zeroes its memory.
相关问答
更多在c ++中可以动态分配的最大内存和编译时间(Maximum memory that can be allocated dynamically and at compile time in c++)
确定C中动态分配的内存大小(Determine size of dynamically allocated memory in C)
“编译时分配的内存”是什么意思?(What does “Memory allocated at compile time” really mean?)
使用动态分配和静态分配的共享内存(Using both dynamically-allocated and statically-allocated shared memory)
C / C ++:动态分配内存的按位运算符(C/C++: Bitwise operators on dynamically allocated memory)
在C ++中释放动态分配内存的问题(Issue With Freeing Dynamically Allocated Memory In C++)
在C中动态分配内存的互斥量(Mutex for dynamically allocated memory in C)
在C ++中对动态分配的内存进行碎片整理(Defragmentation of dynamically allocated memory in C++)
MPI_Abort和动态分配的内存(MPI_Abort and dynamically allocated memory)
删除动态分配的内存(Deletion of Dynamically Allocated Memory)
相关文章
更多rails model的一点疑惑。。。。。
Java:IO/NIO篇,读写属性文件(properties)
log4j.properties被自动删除
solrcore.properties定义server是否是master
页面获取ACTION的属性,页面不能弹出JS
Hibernate中如何实现一个model和多个表关联
Backbone.js的技巧和模式
Cannot expose request attribute 'website' because of an existing model object of the same name 的解决方案
ext 中 ajax怎么异步加载js文件 ?
微信XML消息model定义之微信公众平台(一)
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!