我正在尝试建立一个与rails和脊柱,支持离线浏览的应用程序。我在我的模型中遇到了使用Spine.Model.Local的问题。任何人可以解释我,我们如何使用我们的rails和脊柱应用程序中的Spine.Model.Local。谢谢
发布于 2013-11-28 20:21:36
首先阅读创建spine App的完整Spine Documentation。
在花了很多时间之后,我这样做了,并将我的rails模型数据存储到特定的脊柱模型中,并在本地使用它以实现快速响应。
First ::定义脊椎模型,如下所示。
class App.ModelName extends Spine.Model
@configure 'ModelName', 'columeName1', 'columeName2', ....(and other column)
@extend Spine.Model.Local
@extend Spine.Model.Ajax
# other methods, variables, etc.
# define your methodsSecond ::现在使用ajax通过rails同步特定模型的数据,并将其放在本地存储中,如下所示……
//Request for sync model data for current login user
Spine.Ajax.queue(function() {
$.ajax({
contentType : "application/json",
dataType : "json",
headers : {
"X-Requested-With" : "XMLHttpRequest"
},
url : "/yourDesiredURL.json",
type : "get",
success : function(data, status, xhr) {
for (key in data) {
window.localStorage[key] = JSON.stringify(data[key])
}
new App({
el : $("#app")
});
},
error : function(xhr, statusText, error) {
// Do what do you want to do
}
});
}); 现在,您所需的模型数据已填充到本地存储中,并准备好使用Spine (javascript MVC框架)。
发布于 2013-04-12 05:17:46
假设您已经为localStorage使用http://www.spinejs.com/docs/local查看了Spine.js上的文档,那么您有什么具体的问题?
https://stackoverflow.com/questions/15267505
复制相似问题