2013-07-25 48 views

回答

1

他们有很大的不同:

观察

观察,在那里你可以得到每当值改变事件观察对象:

var ob = new can.Observe({ 
    name: 'Test' 
}); 

ob.bind('change', function(ev, attr, how, newVal, oldVal) { 
    console.log('Something on ob changed, the new value is: ' + newVal); 
}); 

ob.attr('name', 'Changed'); 

这可以在很多地方是有用的,使视图绑定是可能的(所以当使用Observe渲染视图时,只要您自动更新Observe,您的HTML就会更改)。阅读更多关于它in the documentation

灯具

夹具只是模仿AJAX响应,可以帮助你测试你的应用程序或实现 功能,即使你休息后端不起来,但运行:

// Static fixture 
can.fixture("tasks", "fixtures/tasks.json"); 

can.ajax({ 
    url: 'tasks', 
    dataType: 'json' 
}).done(function(data) { 
    // data is the content of fixtures/tasks.json 
    // instead of making a request to tasks 
}); 

// Dynamic fixture 
can.fixture("/foobar.json", function(original, response){ 
    response(200, "success", { json: {foo: "bar" } }, {}) 
}); 

如果双方走到一起是在使用Models时。模型基本上只是从REST后端获取数据的观察。 More on Models and fixtures

+0

什么是你在can.observe中提到的ob.bind? – copthen

+0

您需要的所有信息应在入门指南和文档中:http://canjs.com/docs/can.Observe.prototype.bind.html – Daff

相关问题