【发布时间】:2019-01-22 08:51:52
【问题描述】:
我正在使用 Vue.js 应用程序开发 Sails(最新版本 1.x),在我的 names.page.js 中,我有
data: { names : [], //… },
beforeMount: function() {
// Attach any initial data from the server.
_.extend(this, SAILS_LOCALS);
this.names = [{id: 1, name: 'abc'}, {id:2, name: 'xyz'}]
},
我可以成功进入names.ejs 并显示对象的名称数组。
<pre>{{names}}</pre>
现在我把names.page.js中的this.names = [{id: 1, name: 'abc'}, {id:2, name: 'xyz'}]代码去掉,移到view-names.js,如下图:
fn: async function () {
var sampleNames = [{id: 1, name: ‘abc’}, {id:2, name: ‘xyz’}]
// Respond with view.
return {
names : sampleNames
}
}
但是在我的 names.ejs 中,当我给出 <pre>{{names}}</pre> 时,我得到的输出为空数组 [],实际名称数据(对象数组)没有显示。任何人都可以帮我解决我哪里出错了。
【问题讨论】:
标签: javascript vue.js ecmascript-6 sails.js