model.set() 方法的问题
我在设置包含数字属性的模型值时遇到问题。这是示例:
此代码不起作用:
var modelSkeleton = {id: null, name: null};
var model = rx.data.marshal.Json.createModel(modelSkeleton);
var x = {id:22,name:"New name"};
model.set(x);
但是,如果我在 id 值上加引号,它就会起作用:
var modelSkeleton = {id: null, name: null};
var model = rx.data.marshal.Json.createModel(modelSkeleton);
var y = {id:"22",name:"New name"}
model.set(y);
我做错了什么还是这是一个错误?有什么快速解决办法吗?
I am facing problems in setting model values containing numeric properties. Here is the example:
This code does not work:
var modelSkeleton = {id: null, name: null};
var model = rx.data.marshal.Json.createModel(modelSkeleton);
var x = {id:22,name:"New name"};
model.set(x);
However if I put quotes on id value, it works:
var modelSkeleton = {id: null, name: null};
var model = rx.data.marshal.Json.createModel(modelSkeleton);
var y = {id:"22",name:"New name"}
model.set(y);
Am I doing some mistake or this is a bug? Any quick solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 qooxdoo 数据绑定的概念缺少一些内容。为此,您需要知道代码中的第二行在做什么。这个给你带来了一点魔力,它根据你的 JavaScript 对象创建一个 qooxdoo 类,并实例化一个返回的对象。附加到本机 JavaScript 对象的所有属性都将作为 qooxdoo 属性提供,必须使用常用的 getter 和 setter 进行访问。您使用的 set 方法只是解析给定对象并设置包含的每个属性的快捷方式。所以通常这应该可行,但重要的是要知道你在这里做什么,因为当你有更复杂的对象(如数组)时存在限制,这种方法不起作用。
问候,
马丁
顺便提一句。它总是 qx 而不是 rx。 :)
I think there is something missing of the concepts of the qooxdoo data binding. For that, you need to know what your second line in your code is doing. This one brings you a bit of magic which creates a qooxdoo class based on your JavaScript object and instanciates an object of it which is returned. All the properties attached to your native JavaScript object will be available as qooxdoo properties which have to be accessed with the commonly used getter and setter. The set method you use is just a shortcut which parses your given object and sets each property contained. So usually that should work but its important to know what you are doing here because there are restrictions when you have more complex objects like arrays, this way is not working.
Regards,
Martin
Btw. its always qx and not rx. :)