问题标签 [canjs]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
657 浏览

javascript - Validate Dynamic Object using can.Map.Validate

I was looking for form validation in CanJS and came to know about can.Map.Validate plugin http://canjs.com/docs/can.Map.validations.prototype.errors.html

In the below example taken from the documentation itself, we need to give the properties of the object like 'dueDate' before the creating of the object itself

Now my requirement is I want to build a Map which checks whether my field attribute is empty and returns me a suitable error. But the problem is, there are multiple forms on my page and formObject gets generated dynamically. Now in the above scenario before the creation of object itself, you need to allot the property in init method on which validation needs to be performed. It is not good for my requirement as the object is getting build and properties are unknown before the creation of the object. I searched over the web a lot but unable to crack it.

Providing the code for better understanding EJS File: login.ejs

Controller:

Is there any way of validating the dynamic object properties using ca.Map.Validate plugin? How can I access the instance object passed inside the init method?

Thanks in advance :)

0 投票
1 回答
333 浏览

authentication - CanJs 中的身份验证和导航

呈现主页的最佳方式是什么(身份验证后)。假设它有一个 leftNav 和 Content。我们可以在 login.html 中包含这些部分并在清除身份验证后初始化它们的控制器吗?在路由器控制器内部初始化它们是最佳实践吗?can.route 将在其中扮演什么角色?

在这方面找不到太多的例子。

0 投票
2 回答
452 浏览

canjs - CanJs 应用结构

我是canJs的新手。寻找一个好的应用程序结构来构建一个 canjs 应用程序。我想将模型、控制器和视图/模板逻辑分开到单独的文件夹中。canjs 站点中可用的 todo 应用程序是一个简单的应用程序,它将所有内容都写在一个文件中。任何帮助表示赞赏。

提前致谢

0 投票
1 回答
597 浏览

javascript - 使用 CanJS 的多页面应用程序

我正在寻找一种在 CanJS 中从一个 html 页面导航到另一个 html 页面的方法。下面是场景:

index.html 包含一个带有忘记密码链接的登录表单(使用 ejs 构建)。

索引.html

控制.js

我的要求是当我点击忘记密码链接时,当前页面应该导航到 forgotpassword.html。

一种方法是在 ejs 中填充链接的 href 属性,但这不是一个好的做法,因为当前页面控件将失去其意义。我正在寻找优化的解决方案。如果我错了,请纠正我

在 Web 上,我找到了大部分 CanJS 的单页应用程序示例。如果有人可以将我指向多页应用程序演示/示例,那就太棒了。

提前致谢 :)

0 投票
2 回答
202 浏览

ejs - 在 EJS / JMVC / canJs 中查看助手

计划在我的 JMVC 应用程序中使用视图助手。试图在我的 ejs 文件中实现 select_tag 辅助函数,但未能获得所需的结果。下面是代码

在控制器中:

在 Ejs 文件中:

参考 https://code.google.com/p/embeddedjavascript/wiki/ViewHelpers

我们需要偷任何包裹吗?有示例代码吗?

0 投票
1 回答
321 浏览

javascript - 将数据从子点击传递到 CanJS 中的父事件回调

在 CanJS 控制器中,我在另一个单击处理程序中使用单击事件。如何将一些数据从子处理程序传递给父处理程序

我想将 formData 放入 this.options 中。这里this代表对象,someController所以我不能直接在someFormButton点击事件中使用它。

还想知道我是否遵循正确的方法?场景是单击someButtonSelector出现的表单。我想将 formData 放入当前选项对象

0 投票
1 回答
310 浏览

javascript - 如何使用新模型对象刷新当前视图

我正在构建一个简单的任务应用程序,我可以在其中添加新状态。场景是我已经通过调用 can.Model findAll 方法使用预定义的对象数组构建了状态仪表板。视图存储在“dashboard.ejs”中。当我创建新状态时,我将这些数据保存到我的对象数组中,并在保存回调中保存新的数组数据(包括新的数组数据)。现在我的问题是如何用新返回的数据刷新我当前的视图

为此,我是否需要再次创建新控制器的对象,或者我遗漏了什么?

0 投票
3 回答
173 浏览

javascript - 如何在 CanJS 中获取延迟模型的长度?

我得到一个具有如下结构的模型延迟对象:

在此处输入图像描述

如何找出该对象内部存在多少对象(在本例中为三个)。如果我使用Object.keys(myObject).length,它包括对象观察者和其他数据,如 _computeBindings、_bindings 等。我什至hasOwnProperty在计算长度时尝试使用,但它没有给我想要的结果。

我能想到的一种方法是遍历索引并获得最后一个索引值,如下所示:

有这方面的API吗?

0 投票
1 回答
147 浏览

javascript - 尚未准备好的canjs模板模型。数据绑定

我在渲染模板时尚未准备好的对象时遇到问题。因此,它在没有数据绑定的情况下呈现空视图。

使用延迟对象或其他方法来确保数据绑定的正确方法是什么?

我试过用空模型初始化 selectedProject ,但这似乎有点转储方式:

当我需要使用项目的子对象(如项目阶段)时,这也不会解决问题。

编辑:我发现等待项目子对象的方式很尴尬。我绑定了模型更改的处理程序,所以现在即使刷新也有效。有没有更优雅的方法来做到这一点?

0 投票
1 回答
105 浏览

routes - Specific canjs route isn't called on page load with hashtag

What is wrong in the code? expected results: when the page loads like url/case#!open-cases or url/cases#!new then the target route listner('new route' or ':filter-cases route') should be called but it doesn't happen