gpt4 book ai didi

javascript - 离线应用程序中的 Backbone.js

转载 作者:行者123 更新时间:2023-12-02 20:11:21 26 4
gpt4 key购买 nike

我正在使用 Titanium 使用 Web 技术构建桌面应用程序。我决定使用 Backbone.js 作为我的 mvc。问题是应用程序不在服务器上运行。这是我的 Backbone 模型和集合:

     window.Student = Backbone.Model.extend({
initialize: function(){
this.bind("save", this.value_change);
},
value_change: function(){
alert("Student model saved for : " + this.attributes.first_name);
},

urlRoot : http://localhost:8080/student/,
});

window.Students = Backbone.Collection.extend({
model: Student,
url: 'http://localhost:8080/students/',
});

并尝试使用

从服务器获取值
var students = new Students  
students.fetch()

我收到此错误:

message: "'undefined' is not an object (evaluating '$.ajax')"  

我假设这与 url 部分有关。它无法从服务器获取值。有什么想法吗?

最佳答案

问题是 Backbone 将模型保存在服务器上。它通过向您的服务器发送 ajax 请求来实现此目的。你想要做的是覆盖持久化机制

使用backbone.localStorage将状态保存在 localStorage 而不是数据库中

关于javascript - 离线应用程序中的 Backbone.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6922831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com