model.set() 方法的问题

发布于 2024-09-06 10:50:02 字数 474 浏览 3 评论 0原文

我在设置包含数字属性的模型值时遇到问题。这是示例:

此代码不起作用:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无畏 2024-09-13 10:50:02

我认为 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. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文