Backbone.model:对象函数 (a){return new n(a)} 没有方法 'has'
Backbone.model: Object function (a){return new n(a)} has no method 'has'
我确实写了以下代码(*)
当我尝试在我的 js 控制台中运行以下代码(**) 时,
我得到以下结果:
"your attributes are: ", Object // json object taken from the server as I was expecting
Object function (a){return new n(a)} has no method 'has'
为什么我会收到有关has no method 'has'
的问题?
-
(**)
require.config({
baseUrl: "/"
});
require(["js/models/task"], function ( Model ) {
var model = new Model({id: 1});
model.fetch();
console.log(model.attributes);
});
(*)
define([], function () {
var MyModel = Backbone.Model.extend({
initialize: function ()
{
this.bind("change", function () {
console.log("this model has been changed")
});
this.bind("error", function (model, error) {
console.log(error);
})
},
urlRoot: "/",
url: function () {
var base = this.urlRoot || (this.collection && this.collection.url) || "/";
if (this.isNew()) return base;
return base + this.id;
},
validate: function (attribute) {
if (typeof attribute === "object") {
console.log("your attributes are: ", attribute);
}
}
});
return MyModel;
});
fetch
是异步的,因此请尝试以下操作:
require(["js/models/task"], function ( Model ) {
var model = new Model({id: 1});
model.fetch({success: function() {
console.log(model.attributes);
}});
});
相关文章:
- 为什么dijit.form.Select有方法setStore(),而dijit.fform.FilteringSele
- JSPM-是否有方法或需要对捆绑文件进行版本化
- 当用户试图删除indexedDB数据库时,是否有方法执行函数
- Box2dWeb中是否有方法将对象的位置.x输出到console.log()
- 是否有方法在WebCrypto API中获取RSA密钥的组件
- 是否有方法可以快速确定浏览器是否支持启用了cors的图像而不会污染浏览器?
- 是否有方法以编程方式确定私钥是用DER还是PEM编码的?
- 在反序列化JSON对象时,是否有方法将属性名称转换为小写?
- 是否有方法检查特定点(X,Y)是否在SVG元素中
- 是否有方法减少相同if语句的代码
- 在babel编译时是否有方法注入或忽略全局变量?
- Node.js query:是否有方法提示用户自定义大小的数组
- 在检查字符串时,是否有方法包含单词变体(过去时,动名词)
- 当元素不处于悬停状态时,是否有方法获得元素的HOVER样式?
- 是否有方法检测和更改输入值格式
- 解析JSON字符串后是否有方法获得对象属性
- 检查对象是否有方法,而不实例化它
- 在附加到webRequest事件时,是否有方法访问匹配的URL模式
- Chrome扩展API的警报有方法明确,是不按文档工作
- 原始字符串有方法