为什么我会得到一个类型错误在迪朗达尔一个撰写过程中,通过微风查询时?(Why am I gettin

2019-10-18 06:42发布

我碰到的微风和q.js以下错误,当我的视图和模型正在由撰写使用迪朗达尔约束力的声明的约束。 我写在隔离问题的看法,并直到我尝试做一个撰写与它结合它的伟大工程,它抛出这个错误。 我想从我的实体构造函数将所有的自定义属性初始化,也defering我计算的,但这并没有挫败错误的评价研究。 我不知道该框架是导致此问题,或者我自己的代码。 我用我的DataContext延期Q希望,但是我评论它排除这种可能性,回去使用标准的回调函数。

错误:

[Q] Unhandled rejection reasons (should be empty): [TypeError]
Object [object Object] has no method 'isExpanded'
TypeError: Object [object Object] has no method 'isExpanded'?    at domainModel.<anonymous> (http://myApp/App/viewmodels/categoryTreeView.js?v=1.0.0.0:31:59)?    at evaluateImmediate (http://myApp/Scripts/knockout-2.2.1.debug.js:1241:41)?    at Object.ko.dependentObservable (http://myApp/Scripts/knockout-2.2.1.debug.js:1318:9)?    at dmInitializer (http://myApp/App/viewmodels/categoryTreeView.js?v=1.0.0.0:30:29)?    at proto._postInitialize (http://myApp/scripts/breeze.debug.js:2975:13)?    at mergeEntity (http://myApp/scripts/breeze.debug.js:12768:39)?    at processMeta (http://myApp/scripts/breeze.debug.js:12685:24)?    at visitAndMerge (http://myApp/scripts/breeze.debug.js:12665:16)?    at http://myApp/scripts/breeze.debug.js:12972:20?    at Array.map (native)?From previous event:?    at executeQueryCore (http://myApp/scripts/breeze.debug.js:12593:77)?    at proto.executeQuery (http://myApp/scripts/breeze.debug.js:11461:23)?    at Object.getCategories (http://myApp/App/services/datacontext.js?v=1.0.0.0:51:17)?    at viewModel.self.getCategories (http://myApp/App/viewmodels/categoryTreeView.js?v=1.0.0.0:204:17)?    at init (http://myApp/App/viewmodels/categoryTreeView.js?v=1.0.0.0:223:18)?    at new viewModel (http://myApp/App/viewmodels/categoryTreeView.js?v=1.0.0.0:225:9)?    at Object.<anonymous> (http://myApp/App/durandal/composition.js?v=1.0.0.0:317:42)

categorytreeview.js:

define(["services/datacontext"], function (ctx) {
    function domainModel() {
        var self = this;
        self.isSelected = ko.observable(false);
        self.isExpanded = ko.observable(false);

        self.toggleIsExpanded = function () {
            self.isExpanded(!self.isExpanded());
        };
        self.toggleIsSelected = function () {
            self.isSelected(!self.isSelected());
        };
    }
    var dmInitializer = function (item) {
        item.isBranch = ko.computed(function () {
            return item.Children().length > 0 || item.ParentCategory() == null;
        });
        item.isRoot = ko.computed(function () {
            return item.ParentCategory() == null;
        });
        item.isVisible = ko.computed(function() {
            return item.isRoot() || item.ParentCategory().isExpanded();
        }, item);
    };

    ctx.metadataStore.registerEntityTypeCtor("Category", domainModel, dmInitializer);

    function viewModel() {
        var self = this;
        self.categories = ko.observableArray();

        self.getCategoriesCallback = function (data) {
            console.log("callback for getCategories");
            self.categories(data.results);
        };
        self.getCategories = function () {
            ctx.getCategories(self.getCategoriesCallback);
        };
        init = function () {
            self.getCategories();
        };
        init();
    }
    return viewModel;
}

categorytreeview.html

<div id="categoryTreeView">
    <script id="recursiveTemplate" type="text/html">
    <ul data-bind="visible: isVisible">
        <li data-bind="css: { branch: isBranch, leaf: !isBranch(), expanded: isExpanded }">
            <div data-bind="click: toggleIsExpanded"></div>
            <div>
                <input type="checkbox" data-bind="attr: { id: 'c-' + CategoryId() }, value: CategoryId" />
                <label data-bind="text: Name, attr: { for: 'c-' + CategoryId() }"></label>
            </div>
        </li>
        <!-- ko template: { name: 'recursiveTemplate', foreach: Children } --><!-- /ko -->
    </ul>
    </script>
    <div class="css-treeview">
        <!-- ko template: { name: 'recursiveTemplate', foreach: categories } --><!-- /ko --> 
        <div id="dialog-buttons">
            <input type="button"
                value="Cancel" class="btn-cancel">
            <input type="button" value="Save" class="btn-primary pull-right">
        </div>
    </div>
</div>

这是从主视图中,我撰写了失败查看HTML:

<div data-bind="compose: { model: categoryMapModel, activate: true, cacheViews: false }">
</div>

datacontext.js

function getCategories(afterGetCategories) {
    //var deferred = Q.defer();

    var query = breeze.EntityQuery.from("Category")
        .orderBy("ParentCategoryId, Name")
        .expand("Children");

    manager.executeQuery(query)
        .then(function (data) {
            console.log("callback for getCategories");
            //deferred.resolve(data);
            afterGetCategories(data);
        })
        .fail(function (error) { console.log("Error: " + error); });

    //return deferred.promise;
};

更新1:

我已经排除Q.js了一个问题,它只是在堆栈中的最后一个人。 如果我给你我的categoryMapModel()中包含的一切工作正常的初始值。 如果我再点击界面的按钮,删除并重新显示了该视图中,再次一切工作正常。 如果我还等着在设置这个变量activate()是迪朗达尔再次呼吁一切工作得很好方法。

self.categoryMapModel = ko.observable("viewmodels/categoryTreeView");

然而,当用户点击一个按钮,该变量在运行时设置,这时候我得到的错误。 我所看到的是,breeze.js没有附加从我的初始化函数特定实体的自定义属性。 正如你可以从下面的记录看,当它击中命名为“DVD”它弹了类实体。 这个实体,不知什么原因,不包含任何类似的自定义属性的isExpanded()isRoot()是在初始化函数定义。 出所有的实体,这是不具有自定义属性的唯一一个。 有它之后走在了列表中的其他实体,他们都很好。 我看不出任何逻辑,为什么会微风有一个问题,在这种情况下特定的实体,但它是。

世界上有什么我做错了/什么会导致breeze.js忽略初始化函数?

name: Apparel categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: Art categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: Books categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: Electronics categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: Movies categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: root node categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: Blu-ray categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
*name: DVD categoryTreeView.js:269
*properties: entityAspect, IsDeleted, CategoryId, PictureId, Name, Description, IsPublished, ParentCategoryId, CreatedOn, ParentCategory, Picture, Children, AdvertiserCategories, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: reddisc categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: Animation categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: Accessories categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: test categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: test2 categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: test23 categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
name: test categoryTreeView.js:269
properties: isSelected, isExpanded, toggleIsExpanded, toggleIsSelected, entityAspect, CreatedOn, CategoryId, PictureId, Name, Description, IsPublished, IsDeleted, ParentCategoryId, Children, Picture, ParentCategory, AdvertiserCategories, isBranch, isRoot, isVisible, path, _$typeName, entityType, _$interceptor, getProperty, setProperty,  categoryTreeView.js:270
rootCategories needed 
[Q] Unhandled rejection reasons (should be empty): [TypeError]

Answer 1:

我终于明白是怎么回事! 在主视图中我有一件轻而易举的查询扩展到该Category表,然后我加载另一个视图(categoryTreeView)也需要查询Category表。 由于主视图加载第一,有没有电话registerEntityTypeCtor在该视图的Category实体微风基本上从第一查询缓存的任何实体原样。 当我的第二种观点出现时,即使我做叫registerEntityTypeCtor在那里,它不会触发该已经从主视图的查询加载的实体。



文章来源: Why am I getting a TypeError when querying through breeze during a compose in durandal?