[英]ActiveJDBC + Backbone.js Generated attribute name not usable
I am using ActiveJDBC to access a third-party db. 我正在使用ActiveJDBC访问第三方数据库。 There is a column named "users/year".
有一个名为“用户/年”的列。 I am not happy with that but cannot change it.
我对此不满意,但无法更改。 This results is an attribute "users/year" in the json thats the basis for my backbone.js model.
结果是json中的属性“ users / year”,这是我的ribs.js模型的基础。 Now if I want to access that attribute in the following template:
现在,如果我想在以下模板中访问该属性:
<li><%= name+ ' ' + users/year %></li>
Of course it doesn't work. 当然不行了。 I tried escaping but that doesn't work.
我尝试转义,但这不起作用。 Any suggestions?
有什么建议么?
Since I am new to activeJDBC and backbone.js is there a way off mapping the attribute to a acceptable variable name? 由于我是activeJDBC和ebrian.js的新手,所以没有办法将属性映射到可接受的变量名吗? Or other possible solutions for that?
或其他可能的解决方案? Should I switch from activeJDBC to something else?
我应该从activeJDBC切换到其他东西吗?
You could add a parse method to your collection or model to remap your attribute to a usable name: 您可以在集合或模型中添加解析方法,以将属性重新映射为可用名称:
var M = Backbone.Model.extend({
parse: function(resp) {
if (resp['users/year']) {
resp['users_year'] = resp['users/year'];
delete resp['users/year'];
}
return resp;
}
});
and change your template accordingly 并相应地更改模板
<li><%= name+ ' ' + users_year %></li>
A Fiddle http://jsfiddle.net/nikoshr/rnKSD/ 小提琴http://jsfiddle.net/nikoshr/rnKSD/
或者,您也可以使用吸气剂包装器包装模型的动态吸气剂: http : //code.google.com/p/activejdbc/wiki/SettersAndGetters#No_%22standard%22_setters/getters ???
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.