0
我正在使用requirejs与骨干。该脚本无误地运行,但模型 .fetch()不更新模型。这两个文件Backbone.js的是: -骨干提取没有更新模型
在main.js我
'use strict';
require(['pageElements'],function(pageElements){
$(document).ready(function() {
var country = new pageElements.country();
country.fetch({
success: function(e){
console.log(country.get('areaLevelZeroID')); // returns undefined
}
});
});
});
在pageElements.js我
define(function() {
var country = Backbone.Model.extend({
url : 'resources/js/backBoneSandBox/countries.php',
parse: function(data){
newData = JSON.parse(data);
console.log(newData.areaLevelZeroID); // returns 1
return data;
}
});
return (country);
});
凡解析函数返回正确的值,但不更新模型。
资源/ JS/backBoneSandBox/countries.php测试,并返回JSON字符串
{"areaLevelZeroID":"1","areaLevelZeroName":"Afghanistan"}
我必须失去了一些东西很简单,但我看不出什么。提前感谢您提供任何建议。
你为什么要指定你自己的'parse'函数?你的'.php'已经返回JSON,你在'parse'函数中将它重新解释为JSON - 为什么?你能不能一起删除'parse'并再试一次? – Mjh
感谢您关注此事。仍然没有区别。 – mssbcons
如果您在'success'函数中使用这段代码,会发生什么:'console.log(e.toJSON());'? – Mjh