- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
抱歉,如果这是重复的,但我正在浏览 Breezejs.com 上的文档,我想看看我是否可以得到一些关于“最佳实践”的详细说明
我正在使用 .extend 在父对象上加载一些导航属性。当我想向该可观察数组添加实体时,我使用的是模式弹出窗口。我看到在调用模态的 View 中添加了空白实体,但是当我在创建实体并保存可观察数组后关闭模态时,可观察数组不会更新,只会将主页的新实体留空。
http://www.breezejs.com/documentation/navigation-properties说在 Observable 数组中使用 .push() 会将对象添加到数组中,所以只是想知道我是在正确地执行此操作还是有更好的方法。这看起来很有趣的原因是我必须将实体从我的模态返回到我的父 View 然后推送它,我想也许有更好的方法。
编辑
在我的父 View 模型中,我使用 Durandal.js 的 app.js 来显示模态。
var addComment = function () {
rfcommentcreate.responseFormId(responseForm().id());
app.showModal(rfcommentcreate).then(function (modalResult) {
if (!modalResult) { datacontext.cancelChanges(); return false; }
console.log(modalResult); // Just to make sure the result is not null and of the right type
responseForm.responseFormResponseFormComments.push(modalResult);
return true;
});
};
当我在模式上保存时,我将创建的对象传回。
datacontext.saveChanges()
.fail(initFailed)
.fin(complete);
function complete() {
self.modal.close(responseFormComment()); // responseFormComment is the entity that I work on in the modal
}
ResponseForm.ResponseFormResponseFormComments是ResponseForm的导航属性。
上述代码将实体添加到 Breeze 的实体管理器,但 Knockout 在创建后并未对其进行跟踪。这似乎是一个真实的陈述,因为在我的父 View 的 Html 中,我看到了类似这样的东西
: @
来自 HTML 代码
<span data-bind="text: user().fullName"></span> : <span data-bind="text: message"></span> @ <span data-bind="DateTime: commentDt"></span>
在我在模态中创建实体
根据 breezejs.com 上的导航属性页面,如果我正确解释它,应该可以工作。
A:没有,可能是我的错B:有没有更好的方法来跟踪导航属性而不必将它们“推”到数组中?
Notice that we pushed to Orders and not Orders().
最佳答案
KO 可能存在时间问题。我知道这很笨拙,但您可以尝试以下操作(顺便说一句,我更改了函数参数的名称,因为 modalResult
对我来说不直观):
app.showModal(rfcommentcreate).then(function (comment) { if (!comment) { datacontext.cancelChanges(); return false; } console.log(comment); // Just to make sure the result is not null and of the right type responseForm.responseFormResponseFormComments.push(comment); return Q.delay(true,5); // return true after 5 ms to get another JS event loop cycle in. });
我的建议是在最后一行:
return Q.delay(true,5); // return true after 5 ms to get another JS event loop cycle in.
参见Q API reference中的Q.delay
方法.我正在做的是让 KO 有机会听到 Breeze 更新数组引发的事件并做出相应的响应。
如果有从 ResponseFormComment
到 ResponseForm
的后退导航,请不要认为我会插入导航属性(它真的叫做 responseFormResponseFormComments
? "responseForm"两次?),并不是说这有什么问题。
我宁愿写:
comment.responseForm(responseForm); // entity assignment
或
comment.responseFormId(responseForm.id); // foreign key assignment
两者都有更新 responseForm
评论集合的预期副作用。
但回到主要问题......尝试延迟,让我们知道是否可行。有时 KO 和 Breeze 会搞混他们的时机。
关于knockout.js - 在 Breeze 中刷新导航属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16680257/
你能比较一下属性吗 我想禁用文本框“txtName”。有两种方式 使用javascript,txtName.disabled = true 使用 ASP.NET, 哪种方法更好,为什么? 最佳答案 我
Count 属性 返回一个集合或 Dictionary 对象包含的项目数。只读。 object.Count object 可以是“应用于”列表中列出的任何集合或对
CompareMode 属性 设置并返回在 Dictionary 对象中比较字符串关键字的比较模式。 object.CompareMode[ = compare] 参数
Column 属性 只读属性,返回 TextStream 文件中当前字符位置的列号。 object.Column object 通常是 TextStream 对象的名称。
AvailableSpace 属性 返回指定的驱动器或网络共享对于用户的可用空间大小。 object.AvailableSpace object 应为 Drive 
Attributes 属性 设置或返回文件或文件夹的属性。可读写或只读(与属性有关)。 object.Attributes [= newattributes] 参数 object
AtEndOfStream 属性 如果文件指针位于 TextStream 文件末,则返回 True;否则如果不为只读则返回 False。 object.A
AtEndOfLine 属性 TextStream 文件中,如果文件指针指向行末标记,就返回 True;否则如果不是只读则返回 False。 object.AtEn
RootFolder 属性 返回一个 Folder 对象,表示指定驱动器的根文件夹。只读。 object.RootFolder object 应为 Dr
Path 属性 返回指定文件、文件夹或驱动器的路径。 object.Path object 应为 File、Folder 或 Drive 对象的名称。 说明 对于驱动器,路径不包含根目录。
ParentFolder 属性 返回指定文件或文件夹的父文件夹。只读。 object.ParentFolder object 应为 File 或 Folder 对象的名称。 说明 以下代码
Name 属性 设置或返回指定的文件或文件夹的名称。可读写。 object.Name [= newname] 参数 object 必选项。应为 File 或&
Line 属性 只读属性,返回 TextStream 文件中的当前行号。 object.Line object 通常是 TextStream 对象的名称。 说明 文件刚
Key 属性 在 Dictionary 对象中设置 key。 object.Key(key) = newkey 参数 object 必选项。通常是 Dictionary 
Item 属性 设置或返回 Dictionary 对象中指定的 key 对应的 item,或返回集合中基于指定的 key 的&
IsRootFolder 属性 如果指定的文件夹是根文件夹,返回 True;否则返回 False。 object.IsRootFolder object 应为&n
IsReady 属性 如果指定的驱动器就绪,返回 True;否则返回 False。 object.IsReady object 应为 Drive&nbs
FreeSpace 属性 返回指定的驱动器或网络共享对于用户的可用空间大小。只读。 object.FreeSpace object 应为 Drive 对象的名称。
FileSystem 属性 返回指定的驱动器使用的文件系统的类型。 object.FileSystem object 应为 Drive 对象的名称。 说明 可
Files 属性 返回由指定文件夹中所有 File 对象(包括隐藏文件和系统文件)组成的 Files 集合。 object.Files object&n
我是一名优秀的程序员,十分优秀!