منذ Handlebars 4.6.0 ، لا يمكن للقوالب الوصول إلى خصائص وأساليب النموذج الأولي (افتراضيًا). راجع # 1633 للمناقشات والأسباب والمبررات.
توجد خيارات وقت تشغيل لاستعادة السلوك القديم والتحكم فيه (راجع https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access) ، ولكن إذا كنت تستخدم إطار عمل بدلاً من ذلك من قلب المقاود ، قد لا يكون من الواضح كيفية ضبطها.
إذا تلقيت رسالة الخطأ هذه ، فيرجى إضافة تعليق بالمعلومات التالية
express-hbs
، express-handlebars
) يستدعي المقاود عند تسجيل الخطأ؟ (الصق ناتج npm ls handlebars
أو yarn why handlebars
، إذا لم تكن متأكدًا).Handlebars.compile
ووظيفة النموذج الناتجة مباشرةً ، فيجب أن تكون الإجابة هنا https://handlebarsjs.com/api-reference/runtime-options.html#options -to-control-prototype-access. إذا لم تجيب الوثائق على سؤالك أو لم تفهمه ، يرجى طرح السؤال (هنا) حتى يمكن تحسين الوثائق.express-handlebars
بالاشتراك مع mongoose
نماذج Mongoose هي فئات والخصائص ليست "خصائص خاصة" للكائن الأصل.
أنظف طريقة هي التأكد من أن إدخال المقاود هو كائن جافا سكريبت عادي مناسب. يمكن القيام بذلك في Mongoose ، عن طريق الاتصال بـ toJSON()
أو toObject
app.get('/test', function (_req, res) {
Kitten.find({}).then(kittens => {
res.render('test.hbs', {
kittens: kittens.map(kitten => kitten.toJSON())
})
})
});
لا يمكن استخدام runtimeOptions
(أو templateOptions
) المذكورة في التوثيق هنا ، لأن express-handlebars
لا يدعم إعدادها.
الاختراق السريع والقذر (وهو حقًا متطفل ولا أقترحه) ، هو الاستخدام
var handlebarsInstance = Handlebars.create();
handlebarsInstance.compile = function (templateStr, compileOptions) {
// compile template
// return a function that calls the compiled template with `allowProtoPropertiesByDefault` and `allowProtoMethodsByDefault` as runtime-options
// WARNING: People can crash your system by frabricating special templates. Don't use
// this if your users can create templates.
}
app.engine('hbs', expressHandlebars({
handlebars: handlebarsInstance
}));
الرجاء إضافة Rocket-emoji إلى هذا التعليق إذا كنت ترغب في الحصول على Handlebars.createWithAllowedProtoAccess
أو شيء من هذا القبيل يقوم بالجزء الأوسط من أجلك.
لدي هذه المشكلة ولا أعرف كيف أصلحها ، هل يمكنك مساعدتي؟
هل يمكن لأي شخص إخباري بكيفية إصلاح هذا الخطأ عند استخدام المقاود؟
خطأ:
En-US: handlebars: تم رفض الوصول لحل الخاصية "name" لأنها ليست "ملكية خاصة" للشركة الأم.
يمكنك إضافة خيار وقت التشغيل لتعطيل التحقق أو هذا التحذير:
هل يعرف أي شخص كيفية الإبلاغ عن هذا الخطأ عند استخدام المقاود؟
خطأ:
En: handlebars: تم رفض الوصول لحل خاصية "name" لأنها ليست "ملكية خاصة" لوالدك.
يمكنك إضافة خيار وقت التشغيل لتعطيل التحقق أو هذا التحذير:
لي مثل هذا:
المقاود const = تتطلب ('المقاود السريع')
app.engine ('handlebars'، handlebars ({defaultLayout: 'main'}))
app.set ("عرض المحرك"، "المقود")
app.get ('/ payment'، function (req، res) {
Payment.findAll (). then (function (payments) {
res.render ('payment'، {payments: payments})
})
أود استخدام التحسين. في
أود استخدام التحسين. ر
قم بإلقاء نظرة على هذا: https://www.npmjs.com/package/@handlebars/allow -prototype-access
لا يمكن استخدام
runtimeOptions
(أوtemplateOptions
) المذكورة في التوثيق هنا ، لأنexpress-handlebars
لا يدعم إعدادها.
نظرًا لأن المقاود السريعة لا تسمح لك بتعيين خيارات تكوين وقت التشغيل ، فهل يعلم أي شخص طريقة لفرض المقاود السريع لاستخدام المقاود 4.5.3؟
يمكنك استخدام https://www.npmjs.com/package/@handlebars/allow -prototype-access مع express-handlebars
. إنه يلف القالب المترجم بحيث يتم تعيين المعلمات الافتراضية.
مرحبًا نيلز ، لا يمكنني تشغيل هذه الحزمة ، عندما أحاول تشغيل هذه الحزمة ، أتلقى رسالة "خطأ: الوحدة النمطية" مقاود "لا توفر محرك عرض." خطأ. يبدو أن مستخدمًا آخر يواجه مشكلة مماثلة في https://github.com/wycats/handlebars.js/issues/1648 . لقد نشرت نتائجي في نفس الموضوع. شكرا
@ craj1031tx أجبت بـ # 1648.
الأطر:
express-handlebars
بالاشتراك معmongoose
نماذج Mongoose هي فئات والخصائص ليست "خصائص خاصة" للكائن الأصل.
أنظف طريقة هي التأكد من أن إدخال المقاود هو كائن جافا سكريبت عادي مناسب. يمكن القيام بذلك في Mongoose ، عن طريق الاتصال بـ
toJSON()
أوtoObject
app.get('/test', function (_req, res) { Kitten.find({}).then(kittens => { res.render('test.hbs', { kittens: kittens.map(kitten => kitten.toJSON()) }) }) });
لا يمكن استخدام
runtimeOptions
(أوtemplateOptions
) المذكورة في التوثيق هنا ، لأنexpress-handlebars
لا يدعم إعدادها.الاختراق السريع والقذر (وهو حقًا متطفل ولا أقترحه) ، هو الاستخدام
var handlebarsInstance = Handlebars.create(); handlebarsInstance.compile = function (templateStr, compileOptions) { // compile template // return a function that calls the compiled template with `allowProtoPropertiesByDefault` and `allowProtoMethodsByDefault` as runtime-options // WARNING: People can crash your system by frabricating special templates. Don't use // this if your users can create templates. } app.engine('hbs', expressHandlebars({ handlebars: handlebarsInstance }));
الرجاء إضافة Rocket-emoji إلى هذا التعليق إذا كنت ترغب في الحصول على
Handlebars.createWithAllowedProtoAccess
أو شيء من هذا القبيل يقوم بالجزء الأوسط من أجلك.
شكرا يا صاح :)
اترك الصاروخ هناك!
أنا أستخدم Express-Handlebars مع Sequelize.
المقاود npm ls:
+-- [email protected]
| `-- [email protected]
`-- [email protected]
إخراج وحدة التحكم:
Handlebars: Access has been denied to resolve the property "name" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "id" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "email" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "url" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "description" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "createdAt" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
Handlebars: Access has been denied to resolve the property "updatedAt" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
سأحاول حل النمس الخاص بك
الأطر:
express-handlebars
بالاشتراك معmongoose
نماذج Mongoose هي فئات والخصائص ليست "خصائص خاصة" للكائن الأصل.
أنظف طريقة هي التأكد من أن إدخال المقاود هو كائن جافا سكريبت عادي مناسب. يمكن القيام بذلك في Mongoose ، عن طريق الاتصال بـ
toJSON()
أوtoObject
app.get('/test', function (_req, res) { Kitten.find({}).then(kittens => { res.render('test.hbs', { kittens: kittens.map(kitten => kitten.toJSON()) }) }) });
لا يمكن استخدام
runtimeOptions
(أوtemplateOptions
) المذكورة في التوثيق هنا ، لأنexpress-handlebars
لا يدعم إعدادها.الاختراق السريع والقذر (وهو حقًا متطفل ولا أقترحه) ، هو الاستخدام
var handlebarsInstance = Handlebars.create(); handlebarsInstance.compile = function (templateStr, compileOptions) { // compile template // return a function that calls the compiled template with `allowProtoPropertiesByDefault` and `allowProtoMethodsByDefault` as runtime-options // WARNING: People can crash your system by frabricating special templates. Don't use // this if your users can create templates. } app.engine('hbs', expressHandlebars({ handlebars: handlebarsInstance }));
الرجاء إضافة Rocket-emoji إلى هذا التعليق إذا كنت ترغب في الحصول على
Handlebars.createWithAllowedProtoAccess
أو شيء من هذا القبيل يقوم بالجزء الأوسط من أجلك.
يمكننا أيضًا استخدام طريقة lean () كما هو موضح أدناه
app.get('/test', function (_req, res) { Kitten.find().lean().then(kittens => res.render('test.hbs', { kittens: kittens})); });
نظرًا لأن المقاود السريعة لا تسمح لك بتعيين خيارات تكوين وقت التشغيل ، فهل يعلم أي شخص طريقة لفرض المقاود السريع لاستخدام المقاود 4.5.3؟
لقد قمت بإنشاء علاقات عامة للسماح بإضافة خيارات تكوين وقت التشغيل إلى المقاود السريع. https://github.com/express-handlebars/express-handlebars/pull/53
التعليق الأكثر فائدة
الأطر:
express-handlebars
بالاشتراك معmongoose
نماذج Mongoose هي فئات والخصائص ليست "خصائص خاصة" للكائن الأصل.
أنظف طريقة هي التأكد من أن إدخال المقاود هو كائن جافا سكريبت عادي مناسب. يمكن القيام بذلك في Mongoose ، عن طريق الاتصال بـ
toJSON()
أوtoObject
لا يمكن استخدام
runtimeOptions
(أوtemplateOptions
) المذكورة في التوثيق هنا ، لأنexpress-handlebars
لا يدعم إعدادها.الاختراق السريع والقذر (وهو حقًا متطفل ولا أقترحه) ، هو الاستخدام
الرجاء إضافة Rocket-emoji إلى هذا التعليق إذا كنت ترغب في الحصول على
Handlebars.createWithAllowedProtoAccess
أو شيء من هذا القبيل يقوم بالجزء الأوسط من أجلك.