我正在构建的应用程序使用 Ember.js 和 Raphael.js。由于我是 Ember.js 的新手,我在理解如何将两者结合在一起时遇到了一些问题。我已经看过this demo ,但这只是我的一部分。
让我这样表述我的问题:
让我们以"todo" demo from Ember.js's documentation为例举个例子。如何将图像与每个待办事项相关联,并在待办事项未完成时将该图像显示在 Raphael 绘图 Canvas 上?需要说明的是,只有 1 个拉斐尔绘图表面可以显示所有图像。
就像在 Ember.js 演示中一样,我想为我的待办事项信息使用固定装置,但我想添加一个图像字段:
Todos.Todo.FIXTURES = [
{
id: 1,
title: 'Learn Ember.js',
isCompleted: true,
image: 'some.png'
},
{
id: 2,
title: '...',
isCompleted: false,
image: 'some_other.png'
}
];
请耐心等待我,因为我对 Ember.js 的了解不多。我需要知道
- 在何处以及如何初始化 Raphael 绘图表面
- 如何将图像添加到绘图表面,
- 如何根据关联任务的 isCompleted 值切换图像的可见性。
最佳答案
无论您在哪个对象中存储图像完成数据,都需要有一个观察者函数来响应完成状态的变化。在那个函数中,你会做任何必要的事情来从 raphael 添加/删除图像。 (抱歉,我不了解 raphael,所以无法准确告诉您该函数包含什么)。
观察者每次都会被调用到 Object.set('imageCompleted',true/false);
例子:
App.RaphaelPainter = Ember.Object.extend({
imageCompleted:null,
paintOnRaphaelCanvas:function(){
if(this.get('imageCompleted')){
// erase the image from raphael
}
else {
// add the image to raphael
}
}.observes('imageCompleted')
});
关于javascript - 将 Ember.js 与 Raphael.js 一起使用 : How to associate Ember objects with Raphael objects?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17872316/