javascriptMVC 的启动问题
好的,这是一个初学者的问题。我正在尝试使用 javascriptMVC 的 jQueryMX 部分。我尝试阅读文档,但在理解最简单的事情上仍然存在问题。
所以我想开始我的程序,将一些数据放入我的模型中。我的模型应该包含一些选项卡数据。我目前没有与服务器交谈。我只是想开始用一些 JavaScript 来抽取数据。
这就是我到目前为止的想法:
$(document).ready(
function()
{
tab = new Tabs({
tab1:
{
name:'Reuters',
hits:'500'
},
tab2:
{
name:'AP',
hits:'5043'
},
tab3:
{
name:'Sports',
hits:'50'
},
tab4:
{
name:'Cityscape',
hits:'1'
}
});
}
);
$.Model('Tabs',
{
},
{
}
);
好的。所以现在我可能/可能没有将一些数据注入到我的 $.Model 类中。我还没有任何功能或任何东西。我只是希望能够确保我的班级中有数据。
我的问题是: 数据在我的班级中吗?还是我需要对其做更多处理? 如何通过控制台找到数据?
我知道这是初学者的材料。但我需要这个来开始,因为他们的文档中的示例对我来说解释得不够好。
Ok, so this is a beginners question. I am trying to use the jQueryMX part of javascriptMVC. I have tried reading the docs, but I still have problems understanding the simplest things.
So I want to start my program with putting some data into my Model. My model should contain some tab data. I am currently not talking to server. I just want to start pumping the data some javascript.
So here is what I have come up with so far:
$(document).ready(
function()
{
tab = new Tabs({
tab1:
{
name:'Reuters',
hits:'500'
},
tab2:
{
name:'AP',
hits:'5043'
},
tab3:
{
name:'Sports',
hits:'50'
},
tab4:
{
name:'Cityscape',
hits:'1'
}
});
}
);
$.Model('Tabs',
{
},
{
}
);
Ok. So now I may/may not have pumped some data into my $.Model class. I don't have any functions or anything for it yet. I just want to be able to make sure I have the data in my class.
My questions are:
Are the data in my class or do I need to do more to it?
How can I find the data through the console?
I know this is begginners material. But I need this to get started, as the samples in their doc does not explain it good enough for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,您的代码将无法工作。其实你错过了很多东西。
例如,您的模型需要处理程序来保存和读取数据。
您应该看看这个示例: http://javascriptmvc.com/docs.html#!todo< /a>
它解释了从使用处理程序创建模型到本地存储对象的所有内容。
此外,您还应该使用 JS MVC 生成功能创建应用程序和模型:
例如,使用模型“bar”创建新应用程序“foo”:
打开终端并 cd 到您的 js mvc 目录。
执行这些命令后,您应该有一个可用的基本结构。
No, your code will not work. You are missing a lot of things actually.
For example your Model needs handlers for saving and reading data.
You should have a look at this example: http://javascriptmvc.com/docs.html#!todo
It explains everything from creating a model with handlers and storing objects locally.
Also you should create your Apps and Models using the JS MVC generate function:
e.g. for creating a new app "foo" with the model "bar":
open a terminal and cd into your js mvc directory.
after executing these commands you should have a basic structure available.
你的代码有效。正如前面的答案所述,由于 Tabs 类没有实现静态服务方法,您将无法与数据源交互(您将无法以任何方式对实体进行 CRUD 操作,一旦您的对象被垃圾收集,这些实体就会持续存在) )。但是,您的代码定义了一个继承自
$.Model
的Tabs
类,并使用一些数据实例化它。从控制台,您可以访问
tab
变量(因为您已通过不使用var
将其设为全局变量),使用其 attr 或 attrs 方法,然后您将检索用于创建Tabs
实例的数据。您还可以将事件处理程序绑定到实例,将模型类绑定到 jQuery 元素或$.Model
类提供的任何内容(与数据源交互除外)。(我忽略了有关将 jQueryMX 文件本身导入应用程序的方式的任何问题。)
Your code works. As stated in a previous answer, since the Tabs class does not implement the static service methods you will not be able to interact with the datasource (you won't be able to CRUD entities in any way that will persist once your objects are garbage collected). But, your code defines a
Tabs
class which inherits from$.Model
, and instantiates it with some data.From the console you can access the
tab
variable (since you've made it a global variable by not usingvar
), use its attr or attrs methods and you will retrieve the data you used to create theTabs
instance. You could also bind event handlers to the instance, bind the model class to a jQuery element or anything the$.Model
class provides for, except interacting with the datasource.(I am ignoring any issues regarding the way you import the jQueryMX files themselves into your application.)